Reading from a java.sql.BLOB:

HI,I am getting a java.sql.BLOB object from a database. I want it to read it and and put the contants to a string buffer. Can anyone tell how can i do that.
[170 byte] By [Nistelrooya] at [2007-11-26 13:21:48]
# 1
Get the InputStream from the BLOB and write the content to a ByteArrayOuputStream and then convert the byte array contained in this to a String usingString blobAsString = new String(byteArrayOuputStream.getByteArray(), "whatever character encoding the BLOB contains");
sabre150a at 2007-7-7 17:51:53 > top of Java-index,Java Essentials,Java Programming...
# 2
Better yet - get the input stream and wrap it in an InputStreamReader with the appropriate encoding.
malcolmmca at 2007-7-7 17:51:53 > top of Java-index,Java Essentials,Java Programming...
# 3

> Better yet - get the input stream and wrap it in an

> InputStreamReader with the appropriate encoding.

No advantage if he wants the whole as a String. If he wants it line by line then much better.

I never actually get a BLOB, from a ResultSet I always use either the getBinaryStream(int colIndex) method or the getBytes(int colIndex) or the getCharacterStream(int colIndex). I choose whichever one gets me closest to my target form.

sabre150a at 2007-7-7 17:51:53 > top of Java-index,Java Essentials,Java Programming...