Punter Vicky Punter Vicky - 2 months ago 45x
Java Question

How to read Blob data into 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?


This seemed to work fine -

LobHandler lobHandler = new DefaultLobHandler();
List<FrontendData> frontEndDataList = jdbcTemplate.query(getResponseQuery(sessionId), new RowMapper() {
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                // TODO Auto-generated method stub

                FrontendData frontEndData = new FrontendData();
                String operationName = rs.getString("OPERATION_NAME");
                byte[] requestData = lobHandler.getBlobAsBytes(rs,"RESPONSE_MESSAGE");
                frontEndData.setResponse(new String(requestData));

                return frontEndData;