Inserting Clob with NamedParameterJdbcTemplate

后端 未结 3 556
轻奢々
轻奢々 2021-01-12 20:14

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/InsertC

3条回答
  •  广开言路
    2021-01-12 20:44

    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);
    

提交回复
热议问题