6

http://www.java2s.com/Code/Java/Spring/InsertClobData.htmで見たように、通常、lobHandler + JdbcTemplate + PreparedStatementSetter トリプレットを使用して Clob をデータベースに挿入します。

私の質問は、NamedParameterJdbcTemplate でこれを行う方法ですか? 不可思議な PreparedStatementSetter インターフェイスをパラメーターとして受け入れるメソッドはありません。

4

3 に答える 3

11

これは、少なくとも文字列を挿入するときは、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);
于 2011-04-26T17:14:09.677 に答える
0

私はこのようなことをします。明らかに、他のものを使用する場合は、いくつかのパラメーターをいじる必要がある Oracle データベースを使用します。getJdbcTemplate メソッドは、JdbcDaoSupport (Spring ヘルパー クラス) のヘルパー メソッドです。

getJdbcTemplate().execute(new ConnectionCallback() {

        public Object doInConnection(Connection con) throws SQLException, DataAccessException {

            PublishResponseObject responseObject = new PublishResponseObject();
            OracleCallableStatement ocstmt = null;
            CLOB clob = null;

            try {
                clob = createCLOB(xmlString, con);
                ocstmt = (OracleCallableStatement) con.prepareCall("{call schmea.publish(?)}");
                //When in insert mode and update By Pk is specified updates are possible and version numbers will be returned.
                ocstmt.setCLOB(1, clob);
             ...
             }
             finally {
               clob.close()
               stmt.close
            }
于 2011-04-26T21:21:43.927 に答える