2

I'm a newbie of java programming, and I'm trying to learning.

I have a database mysql and I manage the connection with connection Pool, BoneCP is the library that I use.

The code for create a Pool is this:

        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 );

        }

When i need the connection for send query to DB i catch the connection with this line of code: conn = R.database.connectionPool.getConnection();

I think is all ok at this point and I haven't any errors.

After a min the console say this:

     [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)

This is the strange problem!!

Thank very much!!

Andrea Catania
  • 1,361
  • 3
  • 21
  • 37

1 Answers1

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

This seems to imply that you don't have a java MySQL JDBC driver on your classpath, have a look at the available connectors for MySQL and make sure the appropriate JAR including this driver is on your classpath.

MySQL Connectors

NickDK
  • 5,159
  • 2
  • 18
  • 11
  • hello, and big thanks for your answer. I had installed this lib on project's classpath and i'm able to make query to the databse... This error is called after several minute of inactivity, however I'm able again of reconnect to database without problem. The question is what is the cause of this problem!?? XD – Andrea Catania Nov 28 '13 at 08:17
  • when I redeploy the project I got this: SEVERE: The web application [/tom] appears to have started a thread named [BoneCP-pool-watch-thread] but has failed to stop it. This is very likely to create a memory leak. Nov 28, 2013 9:26:49 AM org.apache.catalina.core.ApplicationContext log – Andrea Catania Nov 28 '13 at 08:27