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
精彩评论