Web Hosting Java, JSP, Tomcat 6, J2EE, Servlets, Struts, Jboss
JavaSercer Pages 17.2.2 The Row and Column Classes (Windows web hosting)
January 25, 2007 on 3:41 pm | In Java | JavaSercer Pages 17.2.2 The Row and Column Classes Let’s now look at the Row and Column classes. Example 17.10 shows a part of the Row class constructor. Example 17.10. The Row Class Constructor package com.ora.jsp.sql; import java.util.*; import java.sql.*; import java.sql.Date; import java.math.*; import com.ora.jsp.sql.column.*; public class Row { private Column[] columns; public Row(ResultSet rs) throws SQLException, UnsupportedTypeException { ResultSetMetaData rsmd = rs.getMetaData( ); int cols = rsmd.getColumnCount( ); columns = new Column[cols]; // Note! Columns are numbered from 1 in the ResultSet for (int i = 1; i <= cols; i++) { int type = rsmd.getColumnType(i); switch (type) { case Types.DATE: columns[i - 1] = new DateColumn(rsmd.getColumnName(i), rs.getDate(i)); break; case Types.TIME: columns[i - 1] = new TimeColumn(rsmd.getColumnName(i), rs.getTime(i)); break; ... default: throw new UnsupportedTypeException("Unsupported SQL " + "data type: " + type); } } } The Row class keeps all column values as an array of Column objects. The constructor is called with a ResultSet that has been positioned at a new row by the caller using the next( ) method. It loops through all columns in the row and creates a Column subclass instance for each. The column's datatype, retrieved from the ResultSetMetaData object, is used to decide which Column subclass to create. Similarly to the Value class structure, the Column class structure contains subclasses corresponding to JDBC column datatypes, as shown in Figure 17.3. Two methods provide access to the number of columns and the array of Column objects, shown in Example 17.11. Example 17.11. The Row's getColumnCount( ) and getColumns( ) Methods public int getColumnCount( ) { return columns.length; } public Column[] getColumns( ) { return columns; } Another set of methods can be used to retrieve the value of an individual column, given its name or index. This set of methods contains one pair per supported datatype. Example 17.12 shows the methods for the BigDecimal, boolean, and String types. page 247
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services
No Comments yet
Sorry, the comment form is closed at this time.
...I
just wanted to take the time to say "Thank you!" for our new webmail
system. It's great! Thanks for taking such good care of us.
Thanks
for helping me out. Just for the record, Webhostingjava.net has been a great
web host! So far your support and handling of questions has far
exceeded that of a "larger web hosting company".
I
would like to thank you for helping me with my domain...You have
shown me great patience and professionalism. I would not hesitate to
recommend you to my clients.