Pergunta

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 Spring'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?

Foi útil?

Solução

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

Outras dicas

You could use the following method.

   execute(ConnectionCallback action)

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top