Oracle JDBC Connection KeepAlive

So, you’ve got a spoiled bloated app or a third party library and it’s fond of manopolizing JDBC connections. There are couple of options with Oracle.

1) Server side option: Oracle Database comes with a Dead Client Detection feature where Oracle Server sends a probe. It can be configured by specifying SQLNET.EXPIRE_TIME parameter in sqlnet.ora. The value specified in in minutes.

2) If you control the connection, then there are plenty of option. If you don’t (in case of third party libraries), then TCP KeepAlive may help you. However, Oracle JDBC driver doesn’t provide a good way to customize TCP level parameters. The only way to specify KeepAlive setting is to use TNSEntry. It works with Thin driver. However, on the downside, you need to have connect string in tnsnames.ora. (ENABLE=broken) option will set KeepAlive on TCP socket.
orcl =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

System.setProperty("", "oracle/NETWORK/ADMIN");
OracleDataSource ods = new OracleDataSource();
Properties cp = new Properties();
cp.setProperty("SetBigStringTryClob", "true");

A typical error when a connection is not used for extended period is,
java.sql.SQLException: Io exception: Connection reset
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows( )
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe( )
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe( )
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout( )
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal( )

You can keep the JDBC connection alive this way even if its not used for long time. However, if you are in such situation, get out before you employ this trick. You will be happier. Long time back, we ran into such a library and we found out the root cause and realized that we should pull the rip cord.


5 thoughts on “Oracle JDBC Connection KeepAlive

  1. Hello there! I could have sworn I’ve visited this website before but after browsing through many of the articles I realized it’s new to me.

    Anyhow, I’m certainly happy I discovered it and I’ll be book-marking it and checking back frequently!

  2. Pingback: Mantener viva una conexión JDBC de Oracle | El Blog de rubensa

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: