getBytes() returning too much data  
Author Message
conorbev





PostPosted: 2003-12-5 6:40:00 Top

java-programmer, getBytes() returning too much data Hi,

I'm running postgreSQL 7.2.1 and java se version 1.4.0_01

I'm storing some images in the database as bytea. When I use
result.getBytes() to fetch the data back it ends up being a larger
size than that which is stored in the database. (I'm sure that the
value stored in the database is the correct size) I was testing it out
with a single entry in the table like this: -

rs = stmt.executeQuery("SELECT imageid, name, gender, image,
length(image) FROM images");

And tried this: -

System.out.println(rs.getInt(5));
byte[] imgBytes = new byte[rs.getInt(5)];
imgBytes = rs.getBytes(4);
System.out.println(imgBytes.length);

Even in this case where the first println displays the expected output
the imgBytes array somehow ends up being about 10k too big (the size
increase is consistent)

Does anyone have any idea whats going on and how I might fix it?

Thanks,
Conor