1

I have a requirement that retrieving a connection times out within specified time from the connection pool if there is any problem in the network. This should be handled through a java application.

Basically, want to give timeout to datasource.getConnection() method.

So after some research, I found setLoginTimeout(int seconds) method of DataSource has this functionality in order to notify if a database connection can not be made within the specified seconds.

I applied this on OracleConnectionPoolDataSource which is working fine, but for the Derby client driver it's giving exception as, org.apache.derby.jdbc.ClientDriver does not have any such attribute loginTimeout.

Looking for your kind responses, please do let me know if there any other way to achieve this as per my requirement or anything I need to add/missing or any information related to this.

Server - Resin 3.0

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Satyabrata
  • 21
  • 2
  • 1
    Derby driver does not have such property, I suggest to configure TCP keepalive on OS level. – fg78nc Jun 23 '17 at 15:16
  • A `Driver` is not a `DataSource`, maybe you are looking for [`DriverManager.setLoginTimeout`](http://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html#setLoginTimeout-int-) instead? – Mark Rotteveel Jun 24 '17 at 08:41
  • Hi Mark, Actually we have different third party api's in the application, so if we change in the os level, it will affect that also. – Satyabrata Jun 27 '17 at 05:03
  • Hi, a simple JDBC DriverManager.setLoginTimeout method for Derby client driver does not work. Followed the same as mentioned by the apache group as the link, https://issues.apache.org/jira/browse/DERBY-2026 , file name logintimeout.java.. please help me on this. – Satyabrata Jun 28 '17 at 12:38
  • Rework on this issue after a long time, finally able to achieve this by using c3p0 connection pooling instead of using datasource for derby.C3P0 has checkConnectionTimeout property which exactly works as per my requirement. – Satyabrata Jul 25 '18 at 06:58

1 Answers1

0

finally able to achieve this by using c3p0 connection pooling instead of using datasource for derby.C3P0 has checkoutTimeout property which exactly works as per this requirement.

Satyabrata
  • 21
  • 2