This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
That's not strictly true. Although exceptions are the best way of dealing with an occurance of a showstopping situation there are other ways to do things.
In this example Nicolas wants to just check if the connection is still alive and well which can be done quickly and easily without waiting for an exception to be thrown.
Have a look at the following code which I am using in one of my database access classes:
This simple example checks to see if the connection is alive before it attempts to send a Query. If the connection isn't alive then it attempts a single re-establishment of the connection before failing.
But What if query is already been fired and server is waiting for reply.On the other side Firewall or something else drop the connection before receiving the reply.I am in such a situation
======================== We have such a query which takes more then 2 hours and database is on other machine.But my application server is behind the firewall so this firewall is dropping the ideal connection (waiting for results )after every hour .