1

I am getting the error:

java.sql.SQLException: Configuration file not found
        at org.apache.commons.dbcp.PoolingDriver.getConnectionPool(PoolingDriver.java:137)
        at org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:175)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:270)
        at com.test.sql.Test.main(Model.java:95)

I checked the connection and there's nothing wrong with it. It's just a pool error. If I don't use the pool but open a connection directly (using the connectionFactory below), I can connect and execute a statement and get a result set.

The code to create and use the pool:

    AbandonedConfig cfg = new AbandonedConfig ();
    cfg.setLogAbandoned (true);
    cfg.setRemoveAbandonedTimeout (5);
    cfg.setRemoveAbandoned (true);
    GenericObjectPool connectionPool = new AbandonedObjectPool(null, cfg);
    connectionPool.setTestWhileIdle (true);
    connectionPool.setTestOnBorrow (true);
    connectionPool.setTestOnReturn (true);
    connectionPool.setMaxActive (5);
    connectionPool.setMaxWait (5000);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/Test?user=testuser&password=password",null);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true, cfg);
    poolableConnectionFactory.setValidationQuery ("SELECT 1");

    Class.forName("org.apache.commons.dbcp.PoolingDriver");
    PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
    driver.registerPool("test_pool",connectionPool);


    //This throws the error
    Connection conn = DriverManager.getConnection( "jdbc:apache:commons:dbcp:" );

    //This does too
    //Connection conn = DriverManager.getConnection( "jdbc:apache:commons:dbcp:Test" );

1 Answer 1

1

The issue is with how I was asking for a connection. You need to ask it for your pool underneath Apache's driver URL:

Connection conn = DriverManager.getConnection( 
     "jdbc:apache:commons:dbcp:test_pool"
);

So the format is:

"jdbc:apache:commons:dbcp:" + TheNameOfYourPool
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.