I am new to Java development so apologies in advance if I am asking something stupid.
I am trying to retrieve an image and it's thumbnail from sql database.
I get data from ResultSet
in BinaryStream
format and then convert it to byte[]
.
For thumbnail it works fine and for original image too I am able to retrieve BinaryStream
using getBinaryStream
method But when I convert it to byte[]
, the array remain empty for some reason.
binaryStream = rs.getBinaryStream("image");
thumbBinaryStream = rs.getBinaryStream("thumbnail");
if (binaryStream != null) {
// Tested on following line and I get empty imageBytes
byte[] imageBytes = IOUtils.toByteArray(binaryStream);
thisRecord.put("image", DatatypeConverter.printBase64Binary(imageBytes)); // imageBytes is empty here
}