Home » Open Source » Programming Interfaces » Recover from JDBC failed connection
Recover from JDBC failed connection [message #341083] Sat, 16 August 2008 02:07 Go to next message
bztom33
Messages: 95
Registered: June 2005
Member

I made sure that executeQuery() does not properly time out after
calling setQueryTimeout() by running this loop:


System.err.printf("[%s] establishing connection\n", System.currentTimeMillis());
c = oracleDataSource.getConnection();
System.err.printf("[%s] connection established\n", System.currentTimeMillis());
s = c.createStatement();
s.setQueryTimeout(1);
 
for (;;) {
    System.err.printf("[%s] executing query \n", System.currentTimeMillis());
    r = s.executeQuery("select 1 from dual");
    System.err.printf("[%s] query returned\n", System.currentTimeMillis());
    r.close();
    try { Thread.sleep(1000); } catch (InterruptedException e) { }
}



You can see from the output that it never times out:

[1137290872367] establishing connection
[1137290873514] connection established
[1137290873514] executing query
[1137290873544] query returned
[1137290874550] executing query
[1137290874552] query returned
[1137290875558] executing query
[1137290875560] query returned
[1137290876566] executing query
[1137290876568] query returned
(ethernet cable unplugged...)
[1137290877574] executing query
(i waited a very long time, and nothing happened...)
Re: Recover from JDBC failed connection [message #341084 is a reply to message #341083] Sat, 16 August 2008 02:59 Go to previous message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
If you unplug the cable then driver is unable to send cancel request to the server and then you are unable to receive the answer from it.

Have a look at: http://forums.oracle.com/forums/thread.jspa?threadID=550257
And Metalink notes 412171.1: "Simple Demonstration of the JDBC setQueryTimeout Call to Cancel a Long Running Query" and 70154.1 "JDBC Features and Comparison of Thin & OCI Drivers"

Regards
Michel
Previous Topic: Fatal error: Call to undefined function oci_connect()
Next Topic: Connect string
Goto Forum:
  


Current Time: Thu Mar 28 05:25:03 CDT 2024