aspose file tools*
The moose likes JDBC 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
Bookmark "Set Timeout for Connections" Watch "Set Timeout for Connections" New topic
Author

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!

:jeff
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set Timeout for Connections