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]

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.
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
> 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