Skip site navigation (1) Skip section navigation (2)

"Something unusual has occured" error using PostgreSQL 8.2 with Apache Commons DBCP 1.2.2

From: "Matthew Storer" <matthewstorer(at)fastmail(dot)us>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: "Something unusual has occured" error using PostgreSQL 8.2 with Apache Commons DBCP 1.2.2
Date: 2007-10-23 17:12:16
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
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

But if I try this, all hell breaks loose on the second call to

Connection conn = ConnectionPool.getConnection();
// do stuff with this connection
Connection conn2 = ConnectionPool.getConnection();   // the exception
below would be thrown inside here

org.postgresql.util.PSQLException: Something unusual has occured to
cause the driver to fail. Please report this exception.
        at org.postgresql.Driver.connect(
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)

        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)


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.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(
			return conn;
		} catch (SQLException sqle) {
			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!


Matt Storer


pgsql-jdbc by date

Next:From: Heikki LinnakangasDate: 2007-10-23 18:13:53
Subject: Re: "Something unusual has occured" error using PostgreSQL 8.2 with Apache Commons DBCP 1.2.2
Previous:From: Tom LaneDate: 2007-10-23 15:59:49
Subject: Re: Chinese database name in URL, can I ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group