从云端运行应用程序时遇到以下错误,但从本地运行时不会出现此错误。
Caused by: java.sql.SQLTransientConnectionException: HikariPool-2 - Connection is not available, request timed out after 30000ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:695)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:197)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:162)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:38)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:108)
... 146 more
Caused by: org.postgresql.util.PSQLException: FATAL: invalid value for parameter "TimeZone": "CST"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2825)
at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:175)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:313)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:263)
at org.postgresql.Driver.makeConnection(Driver.java:443)
at org.postgresql.Driver.connect(Driver.java:297)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477)
at com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:725)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:711)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
... 1 more
也尝试过以下设置,但它仍然采用 CST 时区。 浏览了下面提到的多篇文章,但主要讨论的配置仅与 postgre 相关。
https://www.postgresql.org/message-id/[电子邮件受保护] https://www.postgresql.org/message-id/25914.1510934246%40sss.pgh.pa.us
https://postgrespro.com/list/thread-id/1543208
为 jdbc 连接字符串设置 serverTimezone,如下所示。
jdbc:mysql://localhost:3306/test?serverTimezone=UTC
postgre 的当前时区也是 UTC。 以下是用于在 postgre 上显示和设置时区的命令
SHOW TIMEZONE
SET TIMEZONE 'UTC'
没有
serverTimezone
参数,因此驱动程序正在使用为 JVM 配置的时区。如果您不想更改它,可以尝试为服务器进程设置 timezone
参数:
jdbc:mysql://localhost:3306/test?options=-ctimezone=UTC