Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting Clob with NamedParameterJdbcTemplate

I usually use the lobHandler + JdbcTemplate + PreparedStatementSetter triplet to insert my Clob into the database, as I saw on http://www.java2s.com/Code/Java/Spring/InsertClobData.htm

My question is how to do this with a NamedParameterJdbcTemplate? It has no methods accepting the mysterious PreparedStatementSetter interface as a parameter.

like image 958
jabal Avatar asked Apr 26 '11 14:04

jabal


1 Answers

This works without using the PreparedStatementCallback and lobHandler, at least when inserting a string.

NamedParameterJdbcTemplate template; //= new NamedParameterJdbcTemplate(pDs);
String INSERT_STMT = "INSERT INTO MYTABLE (ID, LONG_TEXT) VALUES (:id, :clob)";
MapSqlParameterSource paramSource = new MapSqlParameterSource();
paramSource.addValue("id", 1L, Types.NUMERIC);
paramSource.addValue("clob", "a long long text", Types.CLOB);
template.update(INSERT_STMT, paramSource);
like image 105
Jonas Avatar answered Sep 27 '22 17:09

Jonas