Take the 2-minute tour ×

I need to store large xml data to CLOB and convert back CLOB to String

But the problem is we are using (Spring NamedParameterJdbc template)

SqlParameterSource paramSource = new BeanPropertySqlParameterSource(
this.jdbcTemplate.update(sql, paramSource);

Where PositionResponsesDO has get and set property

private Clob xmlData;

Now I need to convert String data (large) to Clob and Clob to String. Please suggest me best way.

I can't use File operations as it's WebApp

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can use LobHandler and LobCreator to take Clobs and Blobs and turn them into something else.

The Spring documentation discusses them here.

To convert a clob or blob column to something , you can use a query() method on NamedParameterJdbcTemplate that takes a RowMapper.

LobHandler lobHandler = new DefaultLobHandler();
jdbcTemplate.query(sql, paramSource,
    new RowMapper<Void>() {
        public Void mapRow(ResultSet rs, int i) throws SQLException {
            String clobText = lobHandler.getClobAsString(rs, "clobColumnName");                                                
            byte[] blobBytes = lobHandler.getBlobAsBytes(rs, "blobColumnName");                                                
            return null;
share|improve this answer
It works if we are retriving results using RowMapper. But how to use it with BeanPropertySqlParameterSource. Because this Spring utility maps bean properties with db column. So if i mark bean property with String (respective column in db is Clob), will that works? –  Reddy Jul 11 '12 at 5:08
Perhaps you should try using it first... –  nicholas.hauschild Jul 11 '12 at 12:30
add comment

Your Answer


