Thanks for such a nice article. In above example, we have made the id attribute as varchar. I want to make the ID column as integer than varchar. I tried to load the data with integer but getting error. I have couple of questions... 1. Can we load integer data with lob. 2. if yes then how can I load integer with lob?
Thankyou for your feedback, I'm glad you found the article helpful.
If I understand your question, you are really asking two separate questions.
Q1) Can the ID be an integer instead of a varchar?
A1) Yes, just call "lobStmt.setInt(1, id);" instead of "lobStmt.setString(1, id);" Obviously you would need to make appropriate changes to the table definition and change the declaration of id in the Java code from "String id;" to "int id;"
Q2) Can we load integer data into a LOB column?
A2) Yes, but why? If you have some integers, put them in an integer columns. However if you really, really, really wanted/needed to store an integer as a LOB, you would have to options. Option One, convert it to a String and store it in a CLOB. Option Two, create your integer as an Integer object (i.e. a java.lang.Integer) and serialize it as described in Part 3 of this series. When serializing a Java object such as an Integer, you would need to store the serialized representation as a BLOB in the database.
Be aware that when you serialise a java object such as a java.lang.Integer, you might get more than just the integer that you have put in it. That is, a Serialised Integer will likely be a bit bigger than the four (eight?) bytes normally required to store an integer (bigInt) value in the database.
I hope this helps.