在Spring JDBC中,如何在语句上设置RESULT SET HOLDABILITY?

时间:2011-02-03 08:00:58

标签: java spring jdbc spring-jdbc

我想准备resultSetHoldability参数设置为ResultSet.CLOSE_CURSORS_AT_COMMIT的语句:

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

......和prepareCall一样。我目前正在使用Spring的JdbcTemplateSimpleJdbcCall,因为它具有方便的declareParameters()execute(Map paramValues)方法。

那么设置resultSetHoldability的最简单方法是什么?

2 个答案:

答案 0 :(得分:2)

最简单的方法是使用query上的各种JdbcTemplate方法之一,将PreparedStatementCreator个对象作为第一个参数。

你给它一个PreparedStatementCreator对象,它从提供的PreparedStatement构造Connection,并返回它,例如。

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

jdbcTemplate.query(psc, ...);

答案 1 :(得分:0)

您可以使用以下方法。

   execute(ConnectionCallback action)

connectioncallback使您可以访问具有setHoldability方法

的连接对象
相关问题