2

我是java编程的新手,我正在努力学习。

我有一个数据库 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 发送查询时,我使用这行代码捕获连接: conn = 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)

这是个奇怪的问题!!

非常感谢!!

4

1 回答 1

0
No suitable driver found for jdbc:mysql://localhost:3306/test_db

这似乎意味着您的类路径中没有 java MySQL JDBC 驱动程序,请查看 MySQL 的可用连接器并确保包含此驱动程序的适当 JAR 在您的类路径中。

MySQL 连接器

于 2013-11-27T16:01:42.683 回答