Your DriverManager. SetLoginTimeout(1) sets the maximum time in seconds for the driver to wait while connecting to the database. In your case, it's set to 1.
Up vote 1 down vote favorite 1 share g+ share fb share tw.
I tried to set a connection timeout with the following code: public class ConnectionTimeout { public static void main(String args) throws Exception { String entry = "jdbc:oracle:thin:@xxx:1521:xxx"; Connection con=null; Class. ForName("oracle.jdbc.driver. OracleDriver"); DriverManager.
SetLoginTimeout(1); con=DriverManager. GetConnection(entry,"username","password"); Statement s=con.createStatement(); s. Execute("select 1 from dual"); s.close(); con.close(); } } The instance xxx is not existing.
But I get the following exception: Exception in thread "main" java.sql. SQLException: E/A-Exception: Socket is not connected at oracle.jdbc.driver.DatabaseError. ThrowSqlException(DatabaseError.
Java:112) at oracle.jdbc.driver.DatabaseError. ThrowSqlException(DatabaseError. Java:146) at oracle.jdbc.driver.DatabaseError.
ThrowSqlException(DatabaseError. Java:255) at oracle.jdbc.driver. T4CConnection.
Logon(T4CConnection. Java:387) at oracle.jdbc.driver. PhysicalConnection.(PhysicalConnection.
Java:439) at oracle.jdbc.driver. T4CConnection.(T4CConnection. Java:165) at oracle.jdbc.driver.
T4CDriverExtension. GetConnection(T4CDriverExtension. Java:35) at oracle.jdbc.driver.OracleDriver.
Connect(OracleDriver. Java:801) at java.sql.DriverManager. GetConnection(Unknown Source) at java.sql.DriverManager.
GetConnection(Unknown Source) at my.package.connection.timeout. ConnectionTimeout. Main(ConnectionTimeout.
Java:22) How I can implement a timeout to an not existing or available Oracle database instance? Edit: If I set the DriverManager. SetLoginTimeout(30); to 30 second, the exception happens so fast as before!
Java oracle jdbc timeout link|improve this question edited Jan 12 '11 at 13:03The Elite Gentleman20.6k32338 asked Jan 12 '11 at 12:58Tim Krueger945213.
Your DriverManager. SetLoginTimeout(1); sets the maximum time in seconds for the driver to wait while connecting to the database. In your case, it's set to 1.
To have no limit, set setLoginTimeout(0) where 0 means no limit. I hope this helps. Update if your instance xxx doesn't exists, how would you expect your Oracle Driver to connect to the database?
It won't make any difference how long you set your loginTimeout there's not "host" to connect to.
That is not was I mean. I want a small timeout for trying to etablish a connection. I'm confusing about when I set the timeout to 30 seconds!
With 1 and 30 secondes, the exception comes immediately. Or is that OK in my test code? – Tim Krueger Jan 12 '11 at 13:36 @Tim Krueger, see updated post.
That's why the response is immediate, there's no host. – The Elite Gentleman Jan 12 '11 at 13:48.
Because, in java doc, it shows: timeout in senconds. But in implementation of JDBC oracle, it is miliseconds. You can try with measure are miliseconds.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.