用NamedParameterJdbcTemplate插入Clob [英] Inserting Clob with NamedParameterJdbcTemplate
问题描述
我通常使用lobHandler + JdbcTemplate + PreparedStatementSetter三元组将Clob插入数据库中,正如我在 http://www.java2s.com/Code/Java/Spring/InsertClobData.htm
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
我的问题是如何使用NamedParameterJdbcTemplate做到这一点?它没有任何方法可以接受神秘的PreparedStatementSetter接口作为参数.
My question is how to do this with a NamedParameterJdbcTemplate? It has no methods accepting the mysterious PreparedStatementSetter interface as a parameter.
推荐答案
至少在插入字符串时,此方法无需使用PreparedStatementCallback和lobHandler即可工作.
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);
这篇关于用NamedParameterJdbcTemplate插入Clob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!