Friday, 5 October 2007

UpdateableResultSet with BLOB column

When trying to use an UpdateableResultSet with a BLOB column the following error occurs:

Exception in thread "main" java.sql.SQLException: Invalid operation for read only resultset: updateBlob
at oracle.jdbc.driver.SQLStateMapping.newSQLException(
at oracle.jdbc.driver.DatabaseError.newSQLException(
at oracle.jdbc.driver.DatabaseError.throwSqlException(

The code being used looks something like this:

String querySql2 = "SELECT id, col2 FROM blob_test";

stmt = null;
stmt = conn.createStatement
ResultSet rs = null;
rs = stmt.executeQuery(querySql2);;
// Fails at this line with exception
rs.updateBlob(2, inputStreamUpdate);

This occurs because updateBlob(int, realizes that the user is binding a stream with unknown length and throws an exception. To get around this you need to use the following two methods which work fine.
  • updateBlob(int, Blob)
  • updateBlob(int,, long)

See the following documentation for more information on ResultSet's:

No comments: