We help IT Professionals succeed at work.
Get Started

how to set login timout in Oracle JDBC connection.

Farzad Akbarnejad
on
4,676 Views
Last Modified: 2012-05-06
Hello,
I am trying to determine a way to create a timeout for a connection attempt to remote Oracle databases. If the connection isn't created in X seconds or less, regardless of the reason, I need to stop the connection attempt and report a message. Below is the relevant bit of code...I set login timeout in 10 seconds but it seems that it doesn't work. Could of you suggest a way that I can implement such a timer on the connection attempt?

-FA

String url = "jdbc:oracle:thin:@172.16.16.12:1521:sid";
 
        String user = "user";
        String password = "passwd";
 
        try {
            Class.forName(driver);
            DriverManager.setLoginTimeout(10);
            System.out.println("Timeout: " + DriverManager.getLoginTimeout());
            connection = DriverManager.getConnection(url, user, password);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ResourceManager.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ResourceManager.class.getName()).log(Level.SEVERE, null, ex);
        }

Open in new window

Comment
Watch Question
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 41 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE