File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Set Timeout for Connections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Set Timeout for Connections" Watch "Set Timeout for Connections" New topic

Set Timeout for Connections

Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
Hi, All. I've done some searching of the forums and couldn't find an adequate answer to my question. Basically, I'm trying to set the timeout for establishing connections to the database. I've attempted to use the following:

I have a method which contains the above code, and it's purpose is simply to check if a database is online. The problem is, if the database cannot be reached, the above DriverManager will not timeout for approximately 1 minute. It seems to ignore the call to setLoginTimeout().

I certainly appreciate any comments or suggestions. Thanks!

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

I'm not sure the 'appropriate solution' for what you are doing, but you could accomplish the same using threading. Spawn a new thread that outputs some value when its complete. Then from the original program, go to sleep for some amount of time (say 10 seconds) then wake up and check if the thread you were waiting for has outputted its value. If it has not, assume the database is offline and/or could not be reached.

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: Set Timeout for Connections
It's not a secret anymore!