开发者

In Spring JDBC, how to set RESULT SET HOLDABILITY on statements?

开发者 https://www.devze.com 2023-02-08 01:44 出处:网络
I would like to prepare statements with resultSetHoldability parameter set to ResultSet.CLOSE_CURSORS_AT_COMMIT:

I would like to prepare statements with resultSetHoldability parameter set to ResultSet.CLOSE_CURSORS_AT_COMMIT:

PreparedStatement stmnt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency,
    ResultSet.CLOSE_CURSORS_AT_COMMIT)

...and the same for prepareCall. I am currently using Sprin开发者_高级运维g's JdbcTemplate and SimpleJdbcCall, because it has that convenient declareParameters() and execute(Map paramValues) methods.

So what would be the simplest way to set resultSetHoldability?


The easiest way is to use one of the various query methods on JdbcTemplate which take a PreparedStatementCreator object as their first argument.

You give it a PreparedStatementCreator object which constructs the PreparedStatement from the supplied Connection, and returns that, e.g.

PrepatedStatementCreator psc = new PrepatedStatementCreator() {
   public PreparedStatement createPreparedStatement(Connection conn) {
      return conn.prepareStatement(sql, resultSetType, resultSetConcurrency, 
          resultSetHoldability);
   }
}

jdbcTemplate.query(psc, ...);


You could use the following method.

   execute(ConnectionCallback action)

The connectioncallback gives you access to the connection object, which has a setHoldability method

0

精彩评论

暂无评论...
验证码 换一张
取 消