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... Could of you suggest a way that I can implement such a timer on the connection attempt?

...
   String entry = "jdbc:oracle:thin:@" + host + ":" + port + ":" + sid;
   ... 

   Connection con=null;
   Class.forName("oracle.jdbc.driver.OracleDriver");
   con=DriverManager.getConnection(entry,"USERID","PWD");
   Statement s=con.createStatement();
   s.execute(sql);
   s.close();
   con.close();

Recommended Answers

All 2 Replies

Thanks for the solution Ezzaral. It works great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.