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 =
(DESCRIPTION =(ENABLE=broken)
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
System.setProperty("oracle.net.tns_admin", "oracle/NETWORK/ADMIN");
OracleDataSource ods = new OracleDataSource();
ods.setTNSEntryName("orcl");
ods.setDriverType("thin");
ods.setUser("scott");
ods.setPassword("tiger");
ods.setLoginTimeout(2);
Properties cp = new Properties();
cp.setProperty("SetBigStringTryClob", "true");
ods.setConnectionProperties(cp);
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( DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException( DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException( DatabaseError.java:255)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows( T4CPreparedStatement.java:974 )
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe( OracleStatement.java:1054 )
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe( T4CPreparedStatement.java:836 )
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout( OracleStatement.java:1124 )
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal( OraclePreparedStatement.java:3285 )
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.
What was the root cause…we are currently facing SQL IO Exception 17002…query timed out… please share them.
As I site possessor I believe the content material
here is rattling excellent , appreciate it for your hard work.
You should keep it up forever! Best of luck.
Your style is really unique compared to other folks I’ve read stuff from. Thank you for posting when you’ve
got the opportunity, Guess I will just bookmark this blog.
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!