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.
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");
> 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.