commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tra...@spaceprogram.com
Subject RE: Lost connection from connection pool
Date Thu, 17 Apr 2003 14:34:36 GMT
This is really strange.  It turns out I'm not the only person having big problems with DBCP,
but yet so many people rely on it and it seems to be probably one of the weakest connection
pooling systems.  Connection pooling is relatively simple, yet I think DBCP has made it far
too complicated and therefore, lots of errors.  I wonder about all the people that are using
the datasource in Tomcat?

I don't think DBCP should be released as a stable version after seeing all these errors on
this list lately.

Travis

---- Original Message ----
From: Doss Markus <Markus.Doss@rhein-zeitung.net>
Sent: 2003-04-17
To: commons-user@jakarta.apache.org
Subject: Lost connection from connection pool

I'm using tomcat with a connection pool (setup as datasource) using the
following code :
 
private void setupDriver () {
  String contentURI = buildConnectionURL();
  try {
    Class.forName(this.driverName);
    ObjectPool connectionPool = new GenericObjectPool(null);
    ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory(contentURI,null);
            
GenericKeyedObjectPoolFactory opf = new
GenericKeyedObjectPoolFactory(null, 10,
GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, 2000L, 10, true, true,
10000L, 5, 5000L, true);
            
PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory,connectionPool,opf,null,fals
e,true);  
      PoolingDriver driver = new PoolingDriver();
            
      driver.registerPool("myPool",connectionPool);
   } catch (Exception e) {
     e.printStackTrace();
   }
}
 
Database properties comes within a file. While tomcat startup I load a
servlet, so that I have access to this pool. I'm using a lot of
webservices which connect to a mySQL database. For example like these :
 
   query = "select ObjectKey from rw_object where ObjectName = '" +
objectName + "'";
   logger.debug(query);
   
   con = DriverManager.getConnection("jdbc:apache:commons:dbcp:myPool");

   stmt = con.createStatement();
                  
   rs = stmt.executeQuery(query);
   while (rs.next()) {
     objectKey = rs.getString(1);
     count++;
   }
 
   rs.close();
   stmt.close();
   con.close();
 
Sometimes this service failes, because the getConnection from the pool
fails. Theres thrown an exception like this
 
java.lang.NullPointerException
        at com.mysql.jdbc.Connection.execSQL(Unknown Source)
        at com.mysql.jdbc.Connection.execSQL(Unknown Source)
        at com.mysql.jdbc.Connection.setAutoCommit(Unknown Source)
        at
org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingCon
nection.java)
        at
org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingCon
nection.java)
        at
org.apache.commons.dbcp.PoolableConnectionFactory.activateObject(Poolabl
eConnectionFactory.java)
        at
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjec
tPool.java)
        at
org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java)
        at java.sql.DriverManager.getConnection(DriverManager.java:512)
        at java.sql.DriverManager.getConnection(DriverManager.java:193)
        at
redweb.common.soap.service.RWObjectService.getObjectKey(RWObjectService.
java:87)
 
 
What's wrong with my pool or my handling with the connections. I tried
also to close the connection a the finally clause after the exception
was thrown. But this doesn't work either properly. 
 
Has anyone ideas ?
 
Thanks in advance and best regargs 
 
Markus
 
 
 
 


Mime
View raw message