Jdbc2Odbc, Prepared Stmts and Batches... just don't work together.

Hi.

this throws a NegativeArraySizeException on executeBatch:

con.setAutoCommit(false);

PreparedStatement p=con.prepareStatement("insert test_date(txt) values(?)");

p.setString(1, "das");

p.addBatch();

p.setString(1, "sss");

p.addBatch();

p.executeBatch();

con.commit();

p.close();

con.close();

*******************************

this does too:

con.setAutoCommit(false);

PreparedStatement p=con.prepareStatement("insert test_date(txt) values(?)");

p.setString(1, "das");

p.addBatch();

p.executeBatch();

con.commit();

p.close();

con.close();

*******************************

this works fine:

con.setAutoCommit(false);

PreparedStatement p=con.prepareStatement("insert test_date(txt) values(?)");

p.setString(1, "das");

p.addBatch();

p.executeUpdate();

con.commit();

p.close();

con.close();

*******************************

to make things worse, this does not throw any Exception, but instead of a 5, I get 144595456 in the table!!!:

con.setAutoCommit(false);

PreparedStatement p=con.prepareStatement("insert test_date(l) values(?)");

p.setInt(1, 5);

p.addBatch();

p.executeBatch();

con.commit();

p.close();

con.close();

could someone recode Jdbc2Odbc? :))

nikolas/

[1444 byte] By [ngiannG] at [2007-9-26 3:56:53]
# 1
You know the worst part ?! it returns "true" on supportBatch.anybody in the World is capable of use addBatch with prepared statements with any JDBC driver ? Does JDK 1.4 fixes it ?
atorres2 at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

are you sure it isn't throwing any exceptions?I say this because your insert statement is not properly formed (missing the into keyword). Should be:

PreparedStatement p=con.prepareStatement("insert into test_date (txt) values(?)");

just wondering if this is just a typo

Jamie

jlrober at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

PreparedStatement yieldStmt =

dataMgr.conn.prepareStatement(

"INSERT INTO SCHEDULE_MISF_CALCULATION VALUES"

+ " (?,?,?,?)");

while (iterator.hasNext()) {

YieldResultModel model = (YieldResultModel) iterator.next();

yieldStmt.setString(1, model.getScheduleID());

yieldStmt.setString(2, "02/01");//test data

yieldStmt.setString(3, model.getNPT());

yieldStmt.setString(4, "0"); //test data

yieldStmt.addBatch();

}//end while

yieldStmt.executeBatch();

The following worked for me.

darrowj at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Which DBMS/driver are you using? I've had problems in the past with the ODBC/JDBC bridge and batch updates - it didn't seem to support them. As well Oracle has its own implementation of batch updates, I'm not sure if the normal JDBC ones work properly with Oracle.Col
colbell at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
I have the similar code structure but got 'AbstractMethodError' at runtime. Wonder why?
landzg_sun at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

Hi,

As far as I know, this is a bug in the JDBC-ODBC bridge. I used to get the same error and I used a native driver to get around this problem. My database was DB2, and I used a native driver for DB2. One more thing, the JDBC-ODBC bridge is very slow and you will notice the difference once you use the native driver.

There is a batch file usejdbc2.bat which directs the driver to use the jdbc 2.0 specs explicitly. I ran that before actually using the native driver. In the case of a DB2 driver it should be in the directory Sqllib\java12. But I am not sure about the other drivers.

Hope this helps and best wishes,

Nish

kaluloo at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

> You know the worst part ?! it returns "true" on

> supportBatch.

> anybody in the World is capable of use addBatch with

> prepared statements with any JDBC driver ? Does JDK

> 1.4 fixes it ?

Hi,

Yes I was, with a native JDBC driver and using JDK 1.3.1.

Nish

kaluloo at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8
> I have the similar code structure but got> 'AbstractMethodError' at runtime. Wonder why?This is usually occurs when using a driver built for an older version of JDBC and calling a method that only exists in the newer JDBC.
jschell at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
The driver I'm using is the Oracle JDBC driver in the Classes12.zip they ship with v8.1.6
darrowj at 2007-6-29 12:48:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...