} } catch (Exception ex) { } throw new SQLException(”Unknown object type”); } Setting InputStreams As we ll see with ResultSet later, using InputStreams is the recommended way to work with long data (blobs). There are two ways to treat InputStreams when using them as input parameters: Read the entire InputStream when the parameter is set and treat it as a large data object, or defer the read until the statement is executed and read it in chunks at a time. The latter approach is the preferred method because the contents of an InputStream may be too large to fit into memory. Here s what the SimpleText driver does with InputStreams: public void setBinaryStream( int parameterIndex, java.io.InputStream x, int length) throws SQLException { // Validate the parameter index verify(parameterIndex); // Read in the entire InputStream all at once. A more optimal // way of handling this would be to defer the read until execute // time, and only read in chunks at a time. byte b[] = new byte[length]; try { x.read(b); } catch (Exception ex) { throw new SQLException(”Unable to read InputStream: ” + ex.getMessage()); } // Set the data as a byte array setBytes(parameterIndex, b); } But wait, this isn t the preferred way! You are correct, it isn t. The SimpleText driver simply reads in the entire InputStream and then sets the parameter as a byte array. I ll leave it up to you to modify the driver to defer the read until execute time. ResultSet The ResultSet class provides methods to access data generated by a table query. This includes a series of get methods which retrieve data in any one of the JDBC SQL type formats, either by column number or by column name. When the issue of providing get methods was first introduced by JavaSoft, some disgruntled programmers argued that
Adult web hosting has rich experience in providing unique solutions for the customer’s needs, just check frontpage web hosting services.

Leave a Reply