How would you detect a lost connection using JDBC in a reliable and an efficient way? Currently I'm using a Vertica JDBC driver. I don't think I can use connection pools as I need to control to which node I'm connected at all times. Things I thought of so far:
- Assume SQLException is a lost connection. Seems unreliable.
- Check ex.getCause and look for a socket exception. Not sure if checking cause is a good practice.
- Check error code which I know is a case for a lost connection. Also seems a bit unreliable.
Edit: I've tried isValid and isClosed. isValid throws an exception and isClosed always returns false regardless.