Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> JDBC Thin: Timeouts
In my code, in order to fetch a record from the Oracle database, I have the following:
statement = connection.createStatement(); currentResult = statement.executeQuery("SELECT X,Y,Z FROM FOOBAR"); boolean gotRow = currentResult.next();
There seems to be a timeout problem in the Oracle Thin JDBC driver because the last row throws an exception from time to time. I mean, the code works fine most of the time, but currentResult.next(); throws an exception occasionnally.
My theory is that the oracle driver doesn't wait for the SELECT to be completed and the Result to be ready before it hands back control to the Java program, thereby causing currentResult.next() to crap out.
Adding an empty for loop to ensure that getNext() is called after the result is ready fixes the problem, but I consider this worakround to be a nasty hack, and I'd rather avoid it if anyone has a better suggestion.
Here's the modified code. Runs slower, but more reliably:
statement = connection.createStatement(); currentResult = statement.executeQuery("SELECT X,Y,Z FROM FOOBAR");
// waste time to give time for the result to be ready to
// hand back the rows.
for (int i=0; i<3000000; i++) {
// do something silly to waste CPU cycles here
int k=1000;
int g=i+(9*5);
k+=g-30000;
}
boolean gotRow = currentResult.next();
Q1. Has anyone encountered this problem?
Q2. If so, did you find a better solution?
Thanks,
Pascal Forget <pascal_at_hasc.com> Received on Mon Feb 16 1998 - 00:00:00 CST
![]() |
![]() |