user2102276
user2102276

Reputation: 99

No suitable driver found by connection pool

I have a play 2.1 app that I am unit testing with junit. My tests are running well and are able to perform their database operations. Clearly the driver (org.postgresql.Driver) is loaded.

However, between tests, it appears that the connection pool is having trouble accessing the driver. Below is an excerpt of a typical sequence from my log. Does anyone know why that connection pool might be having trouble accessing the Driver when the application is fine?

[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

Upvotes: 4

Views: 2225

Answers (3)

agabor
agabor

Reputation: 662

I had the same issue with squeryl. It seems that there is nothing wrong with my code. I think this is what happens: Because of the unit tests my application is started and stopped consecutively many times. Play closes the connections when stopping the application. However if your machine is fast enough, it can ask for new connections at app start-up before the ones used in the last run have been closed. It's just a timing issue. You can solve it either by increasing the max number of db connections or by simply sleeping for a short while in the end of Global's onStop.

Upvotes: 0

user2492069
user2492069

Reputation: 11

I assume that you have placed correctly required driver in /Project/lib folder

1) check the database url configuration in application.conf.

2) add "evolutionplugin=disabled" in the application.conf

3) Refer to http://digitalsanctum.com/2012/05/30/play-framework-2-tutorial-database-access/ , have you add dependency in the build.scala?

Thanks, hope can help up~~

Upvotes: 0

Johann Sell
Johann Sell

Reputation: 11

I had the same problem. In my case, the problem occurred because there where not enough database connections. It seems that play won't close the connections at the end of the block. The documentation tell's another story, so maybe it's an error in play?

Solution 1: You could increase your connections in your application.conf, by changing (http://www.playframework.com/documentation/2.1.0/SettingsJDBC)

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

Solution 2: You could close your connections after usage (http://www.playframework.com/documentation/2.0/ScalaDatabase)

DB.withConnection { conn =>   
  // do whatever you need with the connection   
  conn.close()
}

Upvotes: 1

Related Questions