gpt4 book ai didi

playframework - 连接池找不到合适的驱动程序

转载 作者:行者123 更新时间:2023-12-04 07:29:13 24 4
gpt4 key购买 nike

我有一个 play 2.1 应用程序,我正在使用 junit 对其进行单元测试。我的测试运行良好并且能够执行他们的数据库操作。很明显,驱动程序( org.postgresql.Driver )已加载。

但是,在两次测试之间,连接池似乎无法访问驱动程序。以下是我日志中典型序列的摘录。有谁知道为什么当应用程序正常时连接池可能无法访问驱动程序?

[info] application - QuickWitness Server shutdown...
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null
[error] c.j.b.ConnectionHandle - Database access problem. Killing off all remaining connections in the connection pool. SQL State = 08001
[error] c.j.b.PoolWatchThread - Error in trying to obtain a connection. Retrying in 1000ms
java.sql.SQLException: No suitable driver found for jdbc:postgresql:qw
at java.sql.DriverManager.getConnection(DriverManager.java:602) ~[na:1.6.0_26]
at java.sql.DriverManager.getConnection(DriverManager.java:185) ~[na:1.6.0_26]
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.ConnectionHandle.obtainInternalConnection(ConnectionHandle.java:211) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:170) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:101) [bonecp.jar:0.7.1.RELEASE]
[info] application - QuickWitness Server has started
[debug] application - entering ensureTriggersAndStoredProceduresAreInstalled()
[debug] application - exiting ensureTriggersAndStoredProceduresAreInstalled()
[info] application - logging initialized
[info] application - Register user request from localhost:12345
[info] application - QuickWitness Server shutdown...
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null
[error] c.j.b.ConnectionHandle - Database access problem. Killing off all remaining connections in the connection pool. SQL State = 08001
[error] c.j.b.PoolWatchThread - Error in trying to obtain a connection. Retrying in 1000ms
java.sql.SQLException: No suitable driver found for jdbc:postgresql:qw
at java.sql.DriverManager.getConnection(DriverManager.java:602) ~[na:1.6.0_26]
at java.sql.DriverManager.getConnection(DriverManager.java:185) ~[na:1.6.0_26]
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.ConnectionHandle.obtainInternalConnection(ConnectionHandle.java:211) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:170) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:101) [bonecp.jar:0.7.1.RELEASE]
[info] application - QuickWitness Server has started

最佳答案

我有同样的问题。就我而言,出现问题是因为那里没有足够的数据库连接。似乎 play 不会关闭块末尾的连接。文档讲述了另一个故事,所以也许这是一个错误?

解决方案 1:您可以通过更改在 application.conf 中增加连接
( http://www.playframework.com/documentation/2.1.0/SettingsJDBC )

db.default.partitionCount=2
db.default.maxConnectionsPerPartition=5
db.default.minConnectionsPerPartition=5

解决方案 2:您可以在使用后关闭连接 ( http://www.playframework.com/documentation/2.0/ScalaDatabase )
DB.withConnection { conn =>   
// do whatever you need with the connection
conn.close()
}

关于playframework - 连接池找不到合适的驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15175803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com