使用NamedParameterJdbcTemplate插入Clob

jab*_*bal 6 java database spring clob

我通常使用lobHandler + JdbcTemplate + PreparedStatementSetter三元组将我的Clob插入到数据库中,正如我在http://www.java2s.com/Code/Java/Spring/InsertClobData.htm上看到的那样

我的问题是如何使用NamedParameterJdbcTemplate执行此操作?它没有接受神秘的PreparedStatementSetter接口作为参数的方法.

Jon*_*nas 9

这可以在不使用PreparedStatementCallback和lobHandler的情况下工作,至少在插入字符串时是这样.

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);
Run Code Online (Sandbox Code Playgroud)

  • 恢复这个,我在这里使用Spring 3.0,这很有效.它没有真正记录在哪里或为什么,但它确实如此.我更喜欢这个解决方案,因为SqlLobValue没有实现toString()所以阅读它需要更多的工作. (2认同)