Friday, March 6, 2009

Retrieve BLOB column in Sybase

In one of my recent projects, I was expected to explain something to client, which involved retrieving binary large object data from Sybase! So, you might think, what was the big challenge in this? It's BLOB! Just use the JDBC API and call the getBlob() method of the ResultSet!

Yeps, so, why don't you try that? Give it a try. I used the jconn3 driver to connect to my Sybase database. Driver Class being 'com.sybase.jdbc3.jdbc.SybDriver'. The moment you try to call the getBlob() method, you will get a nice exception stack trace, informing you that this is an unsupported operation! Yeps, its not as straight forward as that!

But don't worry, it actually is even more simple! For fetching the BLOB data all you need to do is:

// build a byte array
byte stuff[] = resultSet.getBytes();

// check the size of the data now
System.out.println("BLOB Size: " + stuff.length);

Congratulations! You have retrieved the BLOB data from a Sybase IMAGE column!!!

No comments: