Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to print a BLOB

 
Tomas Nilson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops.... Totally missed that.. THANKS A LOT!!
/Tomas
(it's working now..)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic