gpt4 book ai didi

带有 BoneCP STRANGE 错误的 Java 连接池

转载 作者:行者123 更新时间:2023-11-28 22:30:39 26 4
gpt4 key购买 nike

我是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)

这是个奇怪的问题!!

非常感谢!!

最佳答案

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

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

MySQL Connectors

关于带有 BoneCP STRANGE 错误的 Java 连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20246793/

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