用NamedParameterJdbcTemplate插入Clob [英] Inserting Clob with NamedParameterJdbcTemplate

查看:118
本文介绍了用NamedParameterJdbcTemplate插入Clob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆