Question

I want to detect when a database is down and I know once the database is down it will throw a SQLException. Using Connection.isValid(). What does the timeout paramter represent? It says:

timeout - - The time in seconds to wait for the database operation used to validate the connection to complete. If the timeout period expires before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database operation.

What does this mean?

Was it helpful?

Solution 2

Well, "database is down" means it does not respond. It's not like it can just tell you "hey, I'm down". So the timeout means how long does this method wait for response, before considering database as offline.

OTHER TIPS

The isValid() method allows you to check the Connection for validity.

For this method you can specify a timeout in seconds, when this timeout runs out before the internal validity check is finished, the method will return false.

This is useful if you don't want your program to wait a long time in case the validity check takes too long.

If you give 0 as input for timeout, no timeout will be applied and your program will wait until the check is complete.

It represent the time to discard the connection if any connection is idle for that much time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top