Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id EFA709F961C for ; Tue, 23 Oct 2007 14:22:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 54618-08 for ; Tue, 23 Oct 2007 14:21:58 -0300 (ADT) X-Greylist: delayed 00:09:50.687244 by SQLgrey-1.7.5 Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by postgresql.org (Postfix) with ESMTP id CE20F9F9B43 for ; Tue, 23 Oct 2007 14:22:07 -0300 (ADT) Received: from compute2.internal (compute2.internal [10.202.2.42]) by out1.messagingengine.com (Postfix) with ESMTP id 57A8733C2E for ; Tue, 23 Oct 2007 13:12:16 -0400 (EDT) Received: from web7.messagingengine.com ([10.202.2.216]) by compute2.internal (MEProxy); Tue, 23 Oct 2007 13:12:16 -0400 Received: by web7.messagingengine.com (Postfix, from userid 99) id 3497E2260A; Tue, 23 Oct 2007 13:12:16 -0400 (EDT) Message-Id: <1193159536.9909.1217408695@webmail.messagingengine.com> X-Sasl-Enc: h7gPs5LLJqOKf3O97m+WJx4wU/P9WH0dRFwLiWGgxJ9L 1193159536 From: "Matthew Storer" To: pgsql-jdbc@postgresql.org Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="ISO-8859-1" MIME-Version: 1.0 X-Mailer: MessagingEngine.com Webmail Interface Subject: "Something unusual has occured" error using PostgreSQL 8.2 with Apache Commons DBCP 1.2.2 Date: Tue, 23 Oct 2007 17:12:16 +0000 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/123 X-Sequence-Number: 17695 Hi - I'm getting a rather disturbing exception that I really hope someone can help me out with. To start, I'm putting together a Java client-server app, where the server side talks to a PostgreSQL database via an Apache Commons DBCP link for connection pooling. Using the code I've included below, I'm able to establish a connection, get database metadata, and execute stored functions perfectly well PROVIDING I DON'T try to call getConnection() again without closing the first connection beforehand. (but it seems to me that doing that ought to work alright, because if I call getConnection() a second time, shouldn't the DBCP code just pull a new connection from the pool, and not, instead, throw this exception?) To recap. This works: Connection conn = ConnectionPool.getConnection(); // this ConnectionPool class is one I wrote, see below for details // do stuff with this connection ConnectionPool.close(conn); // simply closes the connection, catching any exceptions conn = ConnectionPool.getConnection(); // get another connection. this works just fine now that // the the connection has been closed before this call But if I try this, all hell breaks loose on the second call to getConnection(): Connection conn = ConnectionPool.getConnection(); // do stuff with this connection Connection conn2 = ConnectionPool.getConnection(); // the exception below would be thrown inside here EXCEPTION: ---------- org.postgresql.util.PSQLException: Something unusual has occured to cause the driver to fail. Please report this exception. at org.postgresql.Driver.connect(Driver.java:276) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:68) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840) at org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:176) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at myproject.db.ConnectionPool.getConnection(ConnectionPool.java:136) RELATED CODE: ------------- This is the code I use to create the connection pool and register the driver (in my ConnectionPool constructor) - note that this works insofar as I can connect to the database and get metadata and do queries and stuff, so I don't think this code is screwy, but who knows?): // some unrelated stuff up here ... GenericObjectPool pool = new GenericObjectPool(null); pool.setMinIdle(5); pool.setMaxIdle(10); pool.setMaxActive(30); pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); pool.setMaxWait(1000 * 60 * 5); pool.setSoftMinEvictableIdleTimeMillis(1000 * 60 * 30); pool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 10); Properties props = new Properties(); props.setProperty("user", "testuser"); props.setProperty("password", "testpass"); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( "jdbc:postgresql://localhost:5432/testdb", props); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, pool, null, null, false, false); PoolingDriver driver = new PoolingDriver(); driver.registerPool("mydb", pool); ... ------------------------------------------------------------------------ Now, when I want to retrieve a connection, I call ConnectionPool.getConnection(), which is where the problem occurs. Note that line 136 (from the stack trace above) is the "Connection conn = DriverManager..." line in the code below: public static Connection getConnection() throws SQLException { try { Connection conn = DriverManager.getConnection( "jdbc:apache:commons:dbcp:mydb"); return conn; } catch (SQLException sqle) { System.out.println(sqle.getMessage()); sqle.printStackTrace(); throw sqle; } } ------------------------------------ Lastly, here are the versions of the relevant software I'm using: - PostgreSQL 8.2.4 - PostgreSQL JDBC driver 8.2-506.jdbc4 - Java 2 SE 1.6.0_02 - Jakarta Commons Pool 1.3 - Jakarta Commons DBCP 1.2.2 - Microsoft Windows XP SP2 On a possibly related note, I read in the Apache Commons DBCP README that says: "This release of JDBC compiles with and supports JDK 1.3 (JDBC 2.0) and JDK 1.4-1.5 (JDBC 3.0). JDK 1.6 (JDBC 4.0) is not supported by this release." I'd like to try using PostgreSQL's JDBC3 drivers, but the site says that if I'm using Java 1.6 I shouldn't use that, but should use their JDBC4 drivers instead. Any thoughts? Thanks a lot for any help you can provide! Regards, Matt Storer