Inserting Clob with NamedParameterJdbcTemplate

后端 未结 3 554
轻奢々
轻奢々 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:36

    I do something like this, obviously we use an Oracle database if you use something else you will have to fiddle with some of the parameter. The getJdbcTemplate method is a helper method of JdbcDaoSupport (a spring helper class.)

    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
                }
    

提交回复
热议问题