我在 tomcat lib 文件夹中将 Hikari 与 SQL Server 2016 和 sqljdbc4-2.0.jar 一起使用。
我对 db 资源的配置如下:
<Resource name="jdbc/SQLServerDS" auth="Container" type="javax.sql.DataSource"
username="uname"
password="pwd"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://server:port;DatabaseName=dbName"
maxActive="20"
maxIdle="10"
validationQuery="select 1" />
我的数据源配置如下:
@Bean(name = "dataSource")
public DataSource getDataSource() throws NamingException {
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(20);
config.setDataSourceJNDI("java:comp/env/jdbc/SQLServerDS");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("cacheResultSetMetadata", "true");
config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("maintainTimeStats", "false");
return new TransactionAwareDataSourceProxy(
new LazyConnectionDataSourceProxy(new HikariDataSource(config)));
}
我如何知道preparedstatement 缓存是否适用于不同的连接?
我正在使用带有 hibernate v4.3.10.Final 的 Spring 容器管理事务。
另外,为了使缓存起作用,我是否需要启用二级缓存?