You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ol...@ppimedia.de on 2007/08/07 10:33:22 UTC

dbcp: InstanceKeyDataSourcegetConnection, exception during setup Defaults()

Hello,

my webapp uses Sybase jConnect2 5.5, commons-dbcp 1.2.1,
spring framework 2.0.1.
 
My webapp runs fine, but after a few days the following
occurs in InstanceKeyDataSource.getConnection:
com.sybase.jdbc2.jdbc.SybConnectionDeadException: JZ0C0 (stacktrace see
below).
Probably this is because of sybase timeouts and acceptable behaviour.

However, I have the impression that the connection is not properly released.

When this has happend a few times, the pool seems to get exhausted: I get 
"org.apache.commons.dbcp.SQLNestedException: Could not retrieve connection
info from pool",
see stacktrace below.

After a restart, everthing is fine.

I have analyzed the problem and I think there is a bug in the last lines
of 
org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(Stri
ng username, String password)

It says:

-------
Connection con = info.getPooledConnection().getConnection();        
setupDefaults(con, username);
con.clearWarnings();
return con;
-------

I my case, the exception happens in the second line of this snippet,
so no code gets the chance close con and release the resources.

I propose to change it to:

-------
Connection con = info.getPooledConnection().getConnection();    
try
{
  setupDefaults(con, username);
  con.clearWarnings();
  return con;
}
catch (Exception exc)
{
  try
  {
    con.close();
  }
  catch (Exception exc)
  {
    getLogWriter().println("ignoring exception during close: " + exc);  //
uncertain here.
  }
  throw exc;
}
-------		

What do you think?

Best regards and thank you for your effort,

Olli



The two exceptions follow.

-----------------------------

java.sql.SQLException: JZ006: Caught IOException:
com.sybase.jdbc2.jdbc.SybConnectionDeadException: JZ0C0: Connection is
already closed.
	at
com.sybase.jdbc2.jdbc.ErrorMessage.raiseErrorCheckDead(ErrorMessage.java:709
)
	at com.sybase.jdbc2.tds.Tds.handleIOE(Tds.java:3071)
	at com.sybase.jdbc2.tds.Tds.cancel(Tds.java:1412)
	at com.sybase.jdbc2.tds.Tds.cancel(Tds.java:1341)
	at
com.sybase.jdbc2.jdbc.SybStatement.doCancel(SybStatement.java:564)
	at
com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1645)
	at
com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1598)
	at
com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatemen
t.java:89)
	at com.sybase.jdbc2.tds.Tds.setOption(Tds.java:1111)
	at
com.sybase.jdbc2.jdbc.SybConnection.setAutoCommit(SybConnection.java:634)
	at
org.apache.commons.dbcp.cpdsadapter.ConnectionImpl.setAutoCommit(ConnectionI
mpl.java:325)
	at
org.apache.commons.dbcp.datasources.SharedPoolDataSource.setupDefaults(Share
dPoolDataSource.java:212)
	at
org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(Inst
anceKeyDataSource.java:654)
	at
org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(Inst
anceKeyDataSource.java:615)
	at
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSour
ceUtils.java:112)
	at
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSource
Utils.java:77)
	at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:513)
	at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:581)
	at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:610)
	at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:614)
	at
org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:
656)
	at
org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:
668)
	at
org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:694
)
--------------------------------

Servlet.service() for servlet jobaccess threw exception :
org.apache.commons.dbcp.SQLNestedException: Could not retrieve connection
info from pool
	at
org.apache.commons.dbcp.datasources.SharedPoolDataSource.getPooledConnection
AndInfo(SharedPoolDataSource.java:169)
	at
org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(Inst
anceKeyDataSource.java:631)
	at
org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(Inst
anceKeyDataSource.java:615)
	at
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSour
ceUtils.java:112)
	at
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSource
Utils.java:77)
	at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:513)
	at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:581)
	at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:610)
	at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:614)

-- 
  Oliver Matz
  Development
  ppi Media GmbH
  Deliusstrasse 10
  24114 Kiel, Germany
  Geschäftsführer: Norbert Ohl, Martin Ruhle
  Amtsgericht Hamburg, HRB 84308
  phone  +49 (0) 431-53 53 -422
  fax    +49 (0) 431-53 53 -222
  www.ppimedia.de

  Explore your printnet!

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