Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reconnecting to an oracle DB

 
Fabien Bergeret
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My application uses a CustomRegistry on WAS 5 to ensure its security. Works fine most of the time, but if the db is not present at startup, the registry is supposed to loop every 10s to see if the db is back.
The first time, I have the following exception :
java.sql.SQLException: Exception d'E/S: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(DriverManager.java:543)
at java.sql.DriverManager.getConnection(DriverManager.java:194)

Ok, fine, the network cable was purposely unplugged. I plug it back, and every 10s, it still have the same exception : i cannot connect to the database once it has fumbled ...
I can still connect with sqltools, so the db is up. If I stop the application and restart it, it works, so the url, the user and the pass are ok.
Any idea ?
Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fabien,
Can you post the code segment you use to try the connection? It sounds like you might be repeatedly trying the same connection that doesn't work. The alternative is to close the connection and get a new one or use connection pooling.
 
Fabien Bergeret
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code :

When I run the class without the network, I have the following trace (which is perfectly normal):

After this exception, I start the network before the second attempt (it is really started since I can connect to the database with SQLTools), and I still have the same exception ...

[ August 11, 2004: Message edited by: Fabien Bergeret ]

[ August 11, 2004: Message edited by: Fabien Bergeret ]

[ August 11, 2004: Message edited by: Fabien Bergeret ]
[ August 11, 2004: Message edited by: Fabien Bergeret ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fabien,

As Jeanne says, close the connection (con.close()) when you catch the exception. That should solve the problem. Otherwise your subsequent calls to getConnection() are probably just picking up the broken one.

You might need a little more than 10 seconds for it to recover and connect happily.

Jules
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic