Re: Wrong Return Value from statement.executeUpdate(query)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On 20.04.2007 17:50, Joe Weinstein wrote:
Robert Klemme wrote:

Hi Robert! Actually, most of them do. Sybase and SQLServer would
do it exactly like this. Oracle would need a "BEGIN delete ...; delete ...; END;".
I forget the DB2 syntax... This has provided efficient 'home-made' batches
since JDBC 1.0.


Ah! Good to know. Still I'd prefer the batch as access to update counts is easier and you can uniformly use it with multiple DB. JDBC 1.0 is really ancient. :-)

So am I! ;)

*Your* words. ;-)

Unfortunately some drivers can't populate the array with actual
update counts if they really send the batch in one packet, so
they just deliver an array filled with -2! :( Also, some drivers
make suprising tradeoffs to implement the later calls (JDBC 2.0
is so *new*. ;) ). I just captured and examined the network packets
between the latest Oracle 10g driver and the DBMS, doing:

s.addBatch("delete joe where bar = 0");
s.addBatch("delete joe where bar = 1");
s.addBatch("delete joe where bar = 0");
int[] foo = s.executeBatch();
for (int i = 0; i < foo.length; i++) System.out.println("array has " + foo[i] );

It prints out the right numbers, but the network
sniffing proves that the driver does *not* send
the batch in one submission. In order to get the
numbers for the array, the client-DBMS protocol
for Oracle requires that they be sent and executed
individually! Whereas, sniffing:

s.execute("BEGIN delete joe where bar = 0; delete joe where bar = 1; delete joe where bar = 0; END;");

does go and get executed in one packet. So the older
code (as long as you have the DBMS-specific SQL) is
guaranteed to be as fast as it can be, but the later
style may not get the benefit you hope for.

Aaargh! As soon as you start doing things a bit more complex than a simple SQL statement or SP call, all bets are off. One more compatibility quirk in JDBC land. For example accessing meta data - although there is a clear defined interface drivers still choose to interpret arguments differently. These are the kinds of things that defy the purpose of a standard. Oh well...

Thanks for sharing this insight!

Grumbling off into the weekend

robert
.



Relevant Pages

  • RE: Trouble Installing DBD::ODBC with postgresql
    ... Ask your local Oracle ... Windows "Server" license) and install the Windows version of Personal ... ODBC is not remote access to a database, ODBC is a layer on top of ... native drivers to present applications a unique interface. ...
    (perl.dbi.users)
  • Re: Access Oracle Objects via PLSQL from JDBC
    ... In oracle demos I couldn't find a such examples.... ... This example uses a JDBC thin client to call a PLSQL stored ... test.java - this calls the plsql and displays the resultset ... // JDBC Implementation specific connect string ...
    (comp.lang.java.programmer)
  • Re: Trouble Installing DBD::ODBC with postgresql
    ... all you need is a set of Oracle client libraries to compile and run DBD::Oracle on Linux. ... ODBC is not remote access to a database, ODBC is a layer on top of native drivers to present applications a unique interface. ... If you link a C program against an ODBC library, it can communicate with any database for which you can find an ODBC driver. ... If you can establish a TCP connection from your linux box to port 1521 on one of the Sun servers, chances are very good that you can use a native connection. ...
    (perl.dbi.users)
  • Re: Database wars
    ... > Queries with Prevayler are more than 9000 times faster than querying ... > Oracle through JDBC. ...
    (borland.public.delphi.non-technical)
  • Re: FOR UPDATE cannot be specified on a READ ONLY cursor
    ... >> Hello Joe, ... > and lost all the big VAR business like SAP, BANN, Peoplesoft etc. ... Oracle, on the other hand, happened ... got the DBMS ...
    (microsoft.public.sqlserver.jdbcdriver)