File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    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
 
Similar Threads
Maintaining Database Connections w/ JDBC??
Connections Issue
what is connection pooling?
Help in tracking down open database connections
JBOSS Cache Error - WARN [TxInterceptor] Commit failed. Clearing stale locks