java.sql.Blob - TechRepublic
General discussion
June 10, 2002 at 04:51 AM
saju_v

java.sql.Blob

by saju_v . Updated 23 years, 9 months ago

I am unable to store the contents of a blob data (from mySQL database) in a java.sql.Blob
object. When I tried to print the data in the java.sql.Blob object (msgBlob) in the program
given below, only “null” is being printed. Please help. Thank you.

Blob msgBlob = rs.getBlob(“fileName”);
java.io.InputStream in = msgBlob.getBinaryStream();
byte b;
while ((in.read()) > -1)
{
b = (byte)in.read();
System.out.println(b);
}

I tried another way (shown below) but only “null” is being printed:

Blob msgBlob = rs.getBlob(“fileName”);
long len = msgBlob.length();
int leng = (int)len;
byte [] data = msgBlob.getBytes(1, leng);

for (int i = 0; i < leng; i++) { byte b = data; System.out.println(b); }

This discussion is locked

All Comments