January 12th, 2008
into the requested data type. Null values are handled specially; the JDBC API has a wasNull method that will return true if the last column that was retrieved was null: public boolean wasNull() throws SQLException { return lastNull; } The SimpleText driver also supports InputStreams. In our case, the SimpleTextInputStream class is just a simple wrapper around a CommonValue object. Thus, if an application requests the data for a column as an InputStream, the SimpleText driver will get the data as a CommonValue object (as it always does) and create an InputStream that fetches the data from the CommonValue. The getMetaData method returns a ResultSetMetaData object, which is our last class to cover. ResultSetMetaData The ResultSetMetaData class provides methods that describe each one of the columns in a result set. This includes the column count, column attributes, and the column name. ResultSetMetaData will typically be the smallest class in a JDBC driver, and is usually very straightforward to implement. For the SimpleText driver, all of the necessary information is retrieved from the Hashtable of column information that is required for all result sets. Thus, to retrieve the column name: public String getColumnLabel( int column) throws SQLException { // Use the column name return getColumnName(column); } protected SimpleTextColumn getColumn( int col) throws SQLException { SimpleTextColumn column = (SimpleTextColumn) inMemoryColumns.get(new Integer(col)); if (column == null) { throw new SQLException(”Invalid column number: ” + col); } return column;
Find the right website host for you, offering a directory of website hosts, free domain name registration tool, hosting reviews, web hosting ratings and articles for beginners, and tons of other resources, check web hosting ratings for more information.