updating blob in the database using jdbc (looking for driver and database independent way)
Posted on 2007-07-19
I have to add a support of storing/retrieving images from the database. Our product is running Java, and we support different JDBC drivers as well as Oracle 8i and up and SqlServer 2000 and up.
At that point it is clear for me that database field inside of the database table should be defined for Oracle as blob; and for SqlServer as image.
Now I am looking for a way of storing and replacing blobs inside of the database.
I did not find one solution that will be good for all supported databases.
For Oracle I found that in order to update blob using JDBC I have to use PreparedStatement and Select ... for Update. As far as I understand this way it tied with Oracle driver.
For SqlServer all examples that I found were related to Insert statement, not much about the update.
However, I am looking for simple UPDATE table SET ? WHERE ... using PreparedStatement methods.
Is it possible to write such a code that will be working for Oracle and SQLServer as well and will be not driver-dependent?
Any real examples would be greatly appreciated.