1
我是一個java編程的新手,我正在努力學習。Java連接池與BoneCP奇怪的錯誤
我有一個數據庫MySQL和我管理與連接池的連接,BoneCP是我使用的庫。
用於創建池的代碼是這樣的:
BoneCPConfig config = new BoneCPConfig(); // create a new configuration object
config.setJdbcUrl( R.database.url + R.database.dbName); // set the JDBC url
config.setUsername(R.database.userName); // set the username
config.setPassword(R.database.password); // set the password
config.setMinConnectionsPerPartition(2);
config.setMaxConnectionsPerPartition(5);
config.setPartitionCount(3);
try{
connectionPool = new BoneCP(config); // setup the connection pool
}catch(Exception e){
System.out.println(e);
}
當我需要發送請求的連接DB I趕上這一行代碼的連接: 康恩= R.database.connectionPool.getConnection ();
我認爲在這一點上都可以,我沒有任何錯誤。
一分鐘後,控制檯這樣說:
[BoneCP-pool-watch-thread] ERROR com.jolbox.bonecp.BoneCP - Failed to acquire connection to jdbc:mysql://localhost:3306/test_db. Sleeping for 7000 ms. Attempts left: 0
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test_db
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
at com.jolbox.bonecp.BoneCP.obtainInternalConnection(BoneCP.java:269)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:242)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:115)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
[BoneCP-pool-watch-thread] ERROR com.jolbox.bonecp.CustomThreadFactory - Uncaught Exception in thread BoneCP-pool-watch-thread
java.lang.NoClassDefFoundError: com/jolbox/bonecp/hooks/ConnectionState
at com.jolbox.bonecp.ConnectionHandle.markPossiblyBroken(ConnectionHandle.java:382)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:244)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:115)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
這是奇怪的問題!
非常感謝!
你好,非常感謝你的回答。我已經在項目的類路徑中安裝了這個庫,並且我能夠查詢數據庫......這個錯誤是在幾分鐘的不活動之後調用的,但是我可以再次重新連接到數據庫而沒有問題。問題是這個問題的原因是什麼! XD –
當我重新部署項目時,我得到了:SEVERE:Web應用程序[/ tom]似乎已經啓動了一個名爲[BoneCP-pool-watch-thread]的線程,但未能阻止它。這很可能造成內存泄漏。 2013年11月28日上午9點26分49秒org.apache.catalina.core.ApplicationContext日誌 –