[英]Disable NamedParameterJdbcTemplate caching
I want to change result set behavior of NamedParameterJdbcTemplate. 我想更改NamedParameterJdbcTemplate的结果集行为。 (disable result set caching) (禁用结果集缓存)
For example , with postgres jdbc driver you could change it like this: 例如,使用postgres jdbc驱动程序,您可以像这样更改它:
conn = datasource.getConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(50);
How i can achieve it in spring / spring-boot ? 我如何在春季/春季靴子中实现它?
If the goal is to change a fetchSize
then you can do it through a JdbcTemplate
instance: 如果目标是更改fetchSize
那么您可以通过JdbcTemplate
实例来完成:
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
jdbcTemplate.setFetchSize(fetchSize);
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(jdbcTemplate);
UPD UPD
Speaking of cache changing you may try to change a private volatile int cacheLimit
of the NamedParameterJdbcTemplate
instance: 说到缓存更改,您可以尝试更改NamedParameterJdbcTemplate
实例的private volatile int cacheLimit
:
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(jdbcTemplate);
template.setCacheLimit(0);
it possible but i didn't explore it 它可能,但我没有探索它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.