SqlRowSet rs = jdbcTemplate.queryForRowSet(sql, params);
Tips1: jdbcTemplate有很多的ORM化回调操作将返回结果转为对象列表,但很多时候还是需要返回ResultSet,Spring有提供一个类似ResultSet的,实现JDBC3.0 RowSet接口的 Spring SqlRowSet。两个类似的类,RowSet简单的封装了一层resultset,使用起来可能有点区别,使用jdbcTemplate.queryForRowSet()遇到UncategorizedSQLException:Invalid precision value. Cannot be less than zero的异常,原因:
it was caused by Oracle's drivers not correctly supporting the CachedRowSet interface.
解决办法是creating an ResultSetExctractor class that implements ResultSetExtractor and used that to get an OracleCachedRowSet implementation of SqlRowSet. To use this you will need to include the oracle driver jar in your project (used ojdbc5.jar).
Tips2:.注意jdbcTemplate尽量只执行查询操作,莫要进行更新,否则会破坏Hibernate的二级缓存体系。
Tips1: jdbcTemplate有很多的ORM化回调操作将返回结果转为对象列表,但很多时候还是需要返回ResultSet,Spring有提供一个类似ResultSet的,实现JDBC3.0 RowSet接口的 Spring SqlRowSet。两个类似的类,RowSet简单的封装了一层resultset,使用起来可能有点区别,使用jdbcTemplate.queryForRowSet()遇到UncategorizedSQLException:Invalid precision value. Cannot be less than zero的异常,原因:
it was caused by Oracle's drivers not correctly supporting the CachedRowSet interface.
解决办法是creating an ResultSetExctractor class that implements ResultSetExtractor and used that to get an OracleCachedRowSet implementation of SqlRowSet. To use this you will need to include the oracle driver jar in your project (used ojdbc5.jar).
Tips2:.注意jdbcTemplate尽量只执行查询操作,莫要进行更新,否则会破坏Hibernate的二级缓存体系。