Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:31:33+00:00 2026-06-07T08:31:33+00:00

I am trying to setup a boneCP connection and I am getting the following

  • 0

I am trying to setup a boneCP connection and I am getting the following error message:

Exception in thread “main” java.lang.ClassCastException: com.jolbox.bonecp.StatementHandle cannot be cast to com.mysql.jdbc.Statement

The connection seems to work fine but I get stopped out at the query.

Here is my code:

        BoneCP connectionPool = null;
    Connection connection = null;

    try {
        // load the database driver (make sure this is in your classpath!)
        Class.forName("com.mysql.jdbc.Driver");
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    try {
        // setup the connection pool
        BoneCPConfig config = new BoneCPConfig();
        config.setJdbcUrl("jdbc:mysql://192.126.0.0:3306/"); // jdbc url specific to your database, eg jdbc:mysql://127.0.0.1/yourdb
        config.setUsername("root"); 
        config.setPassword("");
        config.setMinConnectionsPerPartition(5);
        config.setMaxConnectionsPerPartition(10);
        config.setPartitionCount(1);
        connectionPool = new BoneCP(config); // setup the connection pool

        connection = connectionPool.getConnection(); // fetch a connection

        if (connection != null){
            System.out.println("Connection successful!");
            Statement stmt = (Statement) connection.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT 1 FROM table"); // do something with the connection.
            while(rs.next()){
                System.out.println(rs.getString(1)); // should print out "1"'
            }
        }
        connectionPool.shutdown(); // shutdown connection pool.
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:31:37+00:00Added an answer on June 7, 2026 at 8:31 am

    This is quite simple: If you use BoneCP, you do not have direct access to the objects of the underlying driver. This applies to connection pools in general, because they usually object proxies to handle resource management (eg close statements, resultsets etc when the connection is returned to the pool). This especially applies to statements as connection pools can (and usually do) also provide statement caching.

    Specifically for BoneCP you should be able to get to the wrapped statement using StatementHandle.getInternalStatement() (although I am not 100% sure about that).

    Although the big question is: why do you need to cast to com.mysql.jdbc.Statement, isn’t the java.sql.Statement interface sufficient for you?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to setup Ember.js with Rails 3.1 and I'm getting the following error
Trying to setup a rails app and getting following error. Any ideas? b/tasks instead.
I am trying to setup Django to use MySQL. I am getting the following
Im trying to setup my asp.net mvc page like the following image: The header
I'm trying to setup a binary socket connection in Flash to a server other
Trying to setup a simple Thread/Poll table mapping. Here is what I have: Threads
When trying to setup a lock (pessimistic), with the following code: em.lock(controlnumbers, LockModeType.WRITE); em.refresh(controlnumbers);
I've been trying to setup a simple replication system. 1 main mongo, 1 backup,
I am trying setup a Java program to connect to a website of my
I am trying to setup meaningful URLs such as http://www.site.com/company/department however it hammers my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.