File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "How to print a BLOB" Watch "How to print a BLOB" New topic

How to print a BLOB

Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
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: in = blob.getBinaryStream();
byte b;
while (( > -1)
b = (byte);
} // 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:

[ 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!!
(it's working now..)
I agree. Here's the link:
subject: How to print a BLOB
It's not a secret anymore!