erhalte ich die Fehlermeldung:Erste Fehler mit DBCP Pool: „java.sql.SQLException: Konfigurationsdatei nicht gefunden“
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)
überprüfte ich die Verbindung und es ist nichts falsch mit ihm. Es ist nur ein Poolfehler. Wenn ich den Pool nicht benutze, sondern direkt eine Verbindung öffne (unter Verwendung der folgenden connectionFactory
), kann ich eine Anweisung verbinden und ausführen und eine Ergebnismenge erhalten.
Der Code zu erstellen und den 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");