Get BLOBs from database, how to get them back
I got the BLOB data from the database and used the below code to put it in a string (rs is ResultSet, file is map), is there a way to return this string value in BLOB columns?
Blob blob = rs.getBlob("FILE_DATA");
if(blob != null) {
byte[] bdata = blob.getBytes(1, (int) blob.length());
String data = new String(bdata);
file.put("FILE_DATA", data);
}
I've tried some suggestions like this but they don't work well.
Blob blbVal = getConnection().createBlob();
byte[] fileData = value.toString().getBytes();
blbVal.setBytes(1, fileData);
cs.setBlob(index, blbVal);
0
source to share
1 answer
I found out that the way I put BLOBs to String is also wrong, if we don't encode BLOB data it will be lost.
I found another post here that solved this problem perfectly. Thanks for the answer BalusC How to represent an image from a database in JSON
0
source to share