JDBC issues with setBinaryStream an AbstractMethodError and a cast

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

In DB2, is it possible to update a table having a BLOB using
a statement such as "SELECT MY_BLOB_FIELD FROM MY_TABLE FOR UPDATE"

Then getting the Blob and writing to the Blob's output stream ?

I'm getting an AbstractMethodError suggesting that the DB2
driver I'm using didn't implement setBinaryStream.

I can update the Blob without writing to an OutputStream,
but I'm migrating a lot of code from Oracle and I'd perfer
not to rewrite about 30 files manipulating blob/clob code.

Here is a specific example :

String sql = "select my_blob from my_table where my_table_id = 3 for
update";
con.setAutoCommit(false);
stmt = con.createStatement();
rs1 = stmt.executeQuery(sql);
if (rs1.next()) {
java.sql.Blob blob = rs.getBlob(1);
OutputStream os = blob.setBinarySteam(); // error occurs here
byte[] data = "Some data";
os.write(data);
os.close();
}
con.setAutoCommit(true);

Um.. I'm using standard DB2 type 2 drivers ...
Might there be a way to get around this by casting to
something DB2 specific (what?) and fetching the
output stream from that? Like

OutputStream os = ((DB2.SOMETHING)blob).getBinaryOutputStream();
 
L

Lee Fesperman

In DB2, is it possible to update a table having a BLOB using
a statement such as "SELECT MY_BLOB_FIELD FROM MY_TABLE FOR UPDATE"

Then getting the Blob and writing to the Blob's output stream ?

I'm getting an AbstractMethodError suggesting that the DB2
driver I'm using didn't implement setBinaryStream.

I can update the Blob without writing to an OutputStream,
but I'm migrating a lot of code from Oracle and I'd perfer
not to rewrite about 30 files manipulating blob/clob code.

Here is a specific example :

String sql = "select my_blob from my_table where my_table_id = 3 for
update";
con.setAutoCommit(false);
stmt = con.createStatement();
rs1 = stmt.executeQuery(sql);
if (rs1.next()) {
java.sql.Blob blob = rs.getBlob(1);
OutputStream os = blob.setBinarySteam(); // error occurs here
byte[] data = "Some data";
os.write(data);
os.close();
}
con.setAutoCommit(true);

Um.. I'm using standard DB2 type 2 drivers ...

Sounds like DB2 doesn't support JDBC 3 java.sql.Blob in those drivers. Before JDBC 3,
you couldn't change the contents of a Blob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top