db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Segel <mse...@segel.com>
Subject Re: I need some advice to choose database for an upcomming job
Date Mon, 07 Nov 2005 20:28:07 GMT
On Monday 07 November 2005 11:43, Oyvind.Bakksjo@sun.com wrote:

This is a good question....

According to "JDBC Database Access with Java"  ISBN 020130995-5 (my copy is 
from 1998...)

In Apendix A "For Driver Writers"  A.1.6 Support Multithreading

"All operations on java.sql objects are required to be thread safe. " ...
[Some fun reading]
"For example, two Statement objects on the same connection can be executed 
concurrently, and their ResultSets can be processed concurrently (from the 
perspective of the developer). ..."

So your code should work in "all" JDBC environments.



> Daniel John Debrunner wrote:
> > Oyvind.Bakksjo@Sun.COM wrote:
> >>Note B: If you're running with autocommit OFF, you should definately not
> >>use the same connection object in multiple simultaneous requests (either
> >>use synchronization or create multiple connections).
> >
> > This is true even with automcommit on. Multiple threads using the same
> > connection with ResultSets will mess with each other, as per the JDBC
> > sprc. An executeQuery by one thread will close any ResultSet any other
> > thread is processing.
> Could you elaborate on this?
> I created a small test program which Prepares two statements in separate
> threads, but uses the same connection object. I execute statement A and
> read a few rows from the resultset in thread 1, execute statement B and
> read a few rows from it in thread 2, do a little interleaved reading,
> then read the rest of the rows from both resultsets in their respective
> threads. Got no exception, indicating that no result set was closed.
> I ran this in autocommit mode in both embedded and client/server mode.
> Code excerpt below, in case my explanation of the test program was unclear:
>              t1.prepareStatement();
>              t2.prepareStatement();
>              t1.executeQuery();
>              t1.showRow();
>              t1.showRow();
>              t1.showRow();
>              t2.executeQuery();
>              t2.showRow();
>              t2.showRow();
>              t2.showRow();
>              t1.showRow();
>              t2.showRow();
>              t1.showAll();
>              t2.showAll();
> I have seen some differing behaviour with respect to this in
> client/server and embedded mode before (that's why I made the test), but
> I couldn't reproduce any issue now.

Michael Segel

View raw message