Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQLCODE and stale connection detection and handling

User563833-OracleJan 23 2008 — edited Nov 20 2014
We would like to detect stale connection and handle it.

We can handle the stale connection either at the time when we get the DB connection from connection pool, or when the connection is actually used.

To handle stale connection at the time when we get the connection requires issuing DB operations to see if the connection is valid. This seems expensive.

So I personally think it is better to handle the stale connection when connection is actually used and SQLException is thrown.

However, I haven't figured out or found information on the following issues. Hope anyone in this forum can help out with your knowledge and ideas.

Regarding Stale connection detection
1. Is it possible to detect stale connection from SQLException? Is it through SQLCODE/SQLSTATE?
2. Where to find the list of SQLCODE? Will it be db vendor specific?

Regarding stale connection handling
1. Usually how to handle the stale connection from connection pool (if it is being detected)? If the connection is just closed, will connection pool purge the connection? How to make sure the stale connection is purged from connection pool?

Any thought or reference on stale connection detection and handling is appreciated.

Thanks a lot.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2008
Added on Jan 23 2008
3 comments
2,334 views