What is the difference between isClose() method and isValid() method in Connection interface?

connection, database, java, sql

Solution

The Javadoc is clear enough.

`isClose()` is only guaranteed to return true if the connection was closed by a call to `Connection.close()`. If the connection was closed due to some errors, `isClose()` will not necessarily return true. Therefore, if it returns true, you can be sure the connection is closed, but if it returns false, you can't be sure.

`isValid()` does the opposite of `isClose()`. It attempts to do a positive check that the connection is still open, by running a database query. If it returns `true`, you know for sure the connection is open. If it returns false, you can't be sure if it's open or not (since the query may be delayed due to some network issues, which prevent it from completing before the given timeout).

Problem

What is the difference between `isClose()` method and `isValid()` method in `Connection` interface? http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html What does it mean by invalid connection? Does it mean connection is open and is not valid? What happens when connection is not valid?

Original source

Related problems