3 回答
TA贡献1829条经验 获得超13个赞
这对我有用Spring Boot 2.3.2.RELEASE
:
application.properties:
spring.datasource.hikari.data-source-properties.oracle.jdbc.timezoneAsRegion=true spring.datasource.hikari.data-source-properties.oracle.jdbc.timestampTzInGmt=true
查看:
@Autowired private DataSource dataSource; : logger.info(dataSource.getConnection().unwrap(OracleConnection.class).getProperties().getProperty("oracle.jdbc.timezoneAsRegion")); logger.info(dataSource.getConnection().unwrap(OracleConnection.class).getProperties().getProperty("oracle.jdbc.timestampTzInGmt"));
输出:
真真
_
TA贡献1828条经验 获得超13个赞
这就像addDataSourceProperty
在您的中添加新的一样简单DataSource
public class DataSource {
private static HikariConfig config = new HikariConfig();
private static HikariDataSource ds;
static {
config.setJdbcUrl( "jdbc_url" );
config.setUsername( "database_username" );
config.setPassword( "database_password" );
....
config.addDataSourceProperty( "oracle.jdbc.timezoneAsRegion" , "true" );
config.addDataSourceProperty( "oracle.jdbc.timestampTzInGmt" , "true" );
ds = new HikariDataSource( config );
}
private DataSource() {}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
}
要验证连接中的设置,您必须先解包以获取 Oracle 连接
def hkConn = DataSource.getConnection()
def conn = hkConn.unwrap(OracleConnection.class);
println conn.getProperties().getProperty("oracle.jdbc.timezoneAsRegion");
println conn.getProperties().getProperty("oracle.jdbc.timestampTzInGmt");
它返回
true
true
使用 HikariCP-2.7.2 和 Oracle 12.1 测试
TA贡献1942条经验 获得超3个赞
你在使用 Spring Boot 吗?
如果您使用的是 Spring Boot,则可以尝试通过属性进行设置:
spring.datasource.hikari.*= # Hikari specific settings
使用 MySQL 的属性文件示例之一:
spring.datasource.hikari.mysql.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.hikari.mysql.jdbc-url=jdbc:mysql://10.0.9.198:3306/develop_report?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true
spring.datasource.hikari.mysql.username=root
spring.datasource.hikari.mysql.password=123456
spring.datasource.hikari.mysql.minimum-idle=5
spring.datasource.hikari.mysql.idle-timeout=180000
spring.datasource.hikari.mysql.maximum-pool-size=20
spring.datasource.hikari.mysql.auto-commit=true
spring.datasource.hikari.mysql.pool-name=Mysql-spring.datasource.hikariCP
spring.datasource.hikari.mysql.max-lifetime=1800000
spring.datasource.hikari.mysql.connection-timeout=30000
spring.datasource.hikari.mysql.connection-test-query=SELECT 1
spring.datasource.hikari.mysql.validation-timeout=5000
添加回答
举报