Punter Vicky Punter Vicky - 1 year ago 774
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?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download