aspose file tools*
The moose likes JDBC and the fly likes How to print a BLOB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to print a BLOB" Watch "How to print a BLOB" New topic
Author

How to print a BLOB

Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
Hey,
I have some data stored in a BLOB in a MySQL database. When I read the data using JDBC and then try to print it, the message is garbled. Does anyone know what I am doing wrong?? This is my code:
java.io.InputStream in = blob.getBinaryStream();
byte b;
while ((in.read()) > -1)
{
b = (byte)in.read();
out.print((char)b);
} // prints out all the bytes in the BLOB value that blob designates

I have checked the BLOB's value in the database and it looks ok.
Thanks, Tomas
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

it looks like a problem with your loop. You only read every second byte:

try something like:


Jamie
[ January 17, 2002: Message edited by: Jamie Robertson ]
Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
Oops.... Totally missed that.. THANKS A LOT!!
/Tomas
(it's working now..)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to print a BLOB