How to read Blob data in a String object using Spring JDBCTemplate


I am trying to use Spring JDBCTemplate to read blob data from a table.

List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);

for(Map<String, Object> row:rows){
    row.get("REQUEST_MESSAGE"); // this is blob

How can I read blob into a Java String object?

You can try retrieving the blob from database as below.

String retrieveBlobAsString = null;
Blob b = row.get("REQUEST_MESSAGE");//cast with (Blob) if required. Blob from resultSet as rs.getBlob(index).
InputStream bis = b.getBinaryStream();
ObjectInputStream ois = new ObjectInputStream(bis);
retrieveBlobAsString = (String) ois.readObject();