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 Reconnecting to an oracle DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Reconnecting to an oracle DB" Watch "Reconnecting to an oracle DB" New topic
Author

Reconnecting to an oracle DB

Fabien Bergeret
Greenhorn

Joined: Aug 10, 2004
Posts: 3
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

Joined: May 26, 2003
Posts: 31069
    
232

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Fabien Bergeret
Greenhorn

Joined: Aug 10, 2004
Posts: 3
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

Joined: Aug 02, 2004
Posts: 823
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reconnecting to an oracle DB