commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shazard" <Shaz...@mits.lv>
Subject common-dbcp_1.1 and common-pool_1.1 question
Date Mon, 29 Dec 2003 16:27:37 GMT
Hi There!

I am getting strange exception all the time!
It does not breaks anything but it is annoying!

As far as I found out it is because of MySQL times out it's connection
and then connecetion evictor finds that out. But it finds it out by
calling
getConnection where the exception is thrown and as result of this
exception
pool manager tries to close() connection and gets more exceptions. 
How should I create my MySQL based connection pool using mensioned
packages
to avoid this problem?

Please help!

Here is exception!

EXCEPTION WHILE DESTROYING OBJECT
org.apache.commons.dbcp.datasources.PooledConnectionAndInfo@63a721
java.lang.NullPointerException
        at
com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection.close(MysqlPooledCon
nection.java:145)
        at
org.apache.commons.dbcp.datasources.KeyedCPDSConnectionFactory.destroyOb
ject(KeyedCPDSConnectionFac
tory.java:184)
        at
org.apache.commons.dbcp.datasources.KeyedCPDSConnectionFactory.connectio
nErrorOccurred(KeyedCPDSCon
nectionFactory.java:307)
        at
com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection.callListener(MysqlPo
oledConnection.java:180)
        at
com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection.getConnection(MysqlP
ooledConnection.java:115)
        at
org.apache.commons.dbcp.datasources.KeyedCPDSConnectionFactory.validateO
bject(KeyedCPDSConnectionFa
ctory.java:204)
        at
org.apache.commons.pool.impl.GenericKeyedObjectPool.evict(GenericKeyedOb
jectPool.java:1042)
        at
org.apache.commons.pool.impl.GenericKeyedObjectPool$Evictor.run(GenericK
eyedObjectPool.java:1201)
        at java.lang.Thread.run(Thread.java:536)

Here is my class

package freelancers.database;

import org.apache.commons.dbcp.datasources.SharedPoolDataSource;
//import org.apache.commons.pool.*;
//import org.apache.commons.pool.impl.*;
import freelancers.util.Utils;
import com.mysql.jdbc.jdbc2.optional.*;

/**
 * <p>Title: Freelancers Web Project</p>
 * <p>Description: Project to gather different IT freelancers &
customers. The
 * web application actually will be database with available freelancers
and
 * available projects.</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: Freelancers</p>
 * @author Janis Olekss aka Shazard
 * @version 1.0
 */

public class MysqlPoolingDataSource extends SharedPoolDataSource {
  com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource dataSource
= null;

  public MysqlPoolingDataSource() {
    dataSource = new
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource();
    this.setConnectionPoolDataSource(dataSource);
    this.setValidationQuery("select 1 from forums limit 1");
    this.setTestOnBorrow(true);
    this.setMinEvictableIdleTimeMillis(30 * 1000 * 60);
    this.setNumTestsPerEvictionRun(3);
    this.setTestWhileIdle(true);
    this.setTimeBetweenEvictionRunsMillis(60*1000);
  }
  public void setServerName(String server) {
    dataSource.setServerName(server);
  }

  public void setPort(int port) {
    dataSource.setPort(port);
  }

  public void setUser(String user) {
    dataSource.setUser(user);
  }

  public void setPassword(String password) {
    dataSource.setPassword(password);
  }

  public void setDatabaseName(String databaseName) {
    dataSource.setDatabaseName(databaseName);
  }

  public void setURL(String url) {
    dataSource.setURL(url);
  }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message