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

时间:2013-03-02 14:55:03

标签: playframework playframework-2.1

我有一个游戏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

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。在我的情况下,出现问题是因为没有足够的数据库连接。似乎播放不会关闭块末尾的连接。文档告诉另一个故事,所以也许这是一个错误的游戏?

解决方案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()
}

答案 1 :(得分:0)

我假设您在/ Project / lib文件夹中放置了正确的驱动程序

1)检查application.conf中的数据库url配置。

2)在application.conf

中添加“evolutionplugin = disabled”

3)请参阅http://digitalsanctum.com/2012/05/30/play-framework-2-tutorial-database-access/,您是否在build.scala中添加了依赖项?

谢谢,希望可以帮助~~

答案 2 :(得分:0)

我和squeryl有同样的问题。似乎我的代码没有任何问题。我认为这是发生的事情:由于单元测试,我的应用程序连续多次启动和停止。播放在停止应用程序时关闭连接。但是,如果您的计算机足够快,它可以在应用程序启动时请求新连接,然后再关闭上次运行中使用的连接。这只是一个时间问题。你可以通过增加数据库连接的最大数量或者在Global的onStop结束时简单地休眠一小段来解决它。