pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthew Storer <matthewstorer@fastmail.us>
To: pgsql-jdbc@postgresql.org
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
Message-ID: <1193159536.9909.1217408695@webmail.messagingengine.com> (raw)

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



view thread (6+ messages)  latest in thread

Message-ID: <1193159536.9909.1217408695@webmail.messagingengine.com>
Permalink:  ../1193159536.9909.1217408695@webmail.messagingengine.com/
Also on:    postgresql.org/message-id/1193159536.9909.1217408695@webmail.messagingengine.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: matthewstorer@fastmail.us
  Subject: Re: "Something unusual has occured" error using PostgreSQL 8.2 with Apache Commons DBCP 1.2.2
  In-Reply-To: <1193159536.9909.1217408695@webmail.messagingengine.com>
  References: <1193159536.9909.1217408695@webmail.messagingengine.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox