Batch Update Error, very strange...

0 views
Skip to first unread message

Gregory M. Sliker

unread,
Oct 26, 2000, 10:11:46 PM10/26/00
to
Can anyone explain why the little test app below produces the weird error
message when it gets to the stmt.executeBatch() statement?

My 'environment' is Java 1.3, MS SQL Server 7, JDBC:ODBC. The table DDL is
at the bottom if you would like to try and duplicate this and tell me where
I went wrong. I tried this at another location using Java 1.2.2 and still
received an error but it was slightly different, along the lines of the
feature not implemented.

Any help will be appreciated and put to use. And thanks in advance for
taking the time to give it the once over...


Greg Sliker

++++++++++++++++++++++++++++++++++++++++++++++++

import java.io.*;
import java.sql.*;

public class batchTest{

static Connection conn = null;
static PreparedStatement stmt = null;
static String url = "jdbc:odbc:mytestdb";

public static void main(String args[]){
doBatch();
}

public static void doBatch(){
String sql1 = "insert into batchTest( " +
"id, " +
"text) " +
"values( " +
"?, " +
"?) ";

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(url, "sa", "");
}
catch (Exception e1) {
System.out.println("Failed to load JDBC:ODBC driver.");
}

try{
stmt = conn.prepareStatement(sql1);
conn.setAutoCommit(false);

for (int idx = 0; idx < 5; idx++){
stmt.setInt(1, idx);
stmt.setString(2, ("IDX=" + idx));
stmt.addBatch();
}

int updCount[] = stmt.executeBatch();
conn.commit();
conn.setAutoCommit(true);
}
catch (Exception e){
e.printStackTrace();
}
}
}

/*
c:\temp>java batchTest
java.lang.NegativeArraySizeException
at
sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(JdbcOdbcPreparedS
tatement.java:1502)
at
sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(JdbcOdbcStatement.java:862)
at batchTest.doBatch(batchTest.java:41)
at batchTest.main(batchTest.java:12)

Table structure is as follows...
TABLE NAME: batchTest
COL NAME DATATYPE COMMENT
id int NOT NULL-PRIMARY KEY
text char(10) NULL
*/


george_...@my-deja.com

unread,
Oct 27, 2000, 1:08:29 AM10/27/00
to
The JDBC ODBC bridge does not support Batch Updates.
Try AveConnect 2.3 from Atinav.

Website: www.avenir.net


Sent via Deja.com http://www.deja.com/
Before you buy.

nichola...@my-deja.com

unread,
Oct 27, 2000, 1:12:17 AM10/27/00
to

I feel it is not the problem of your code.I tried the same code with
other drivers. They are working.I feel jdbcodbc driver doesnot support
batchupdates.Try with aveconnect2.3 or Jtubo.

Gregory M. Sliker

unread,
Oct 27, 2000, 6:23:22 AM10/27/00
to
Thanks to both of you for taking the time to answer my question. I was a
little afraid that it might be a 'bridge' problem but I had never tried the
batch methods before. My new assignment has placed a few restrictions on
what I can and can not do as far as development goes, so I felt compelled to
give everything supplied to me my best shot.

Here's another question that maybe you can help with. Is there some summary
documentation out there that describes just what the JDBC:ODBC bridge does
and does not support? A matrix diagram of some sort? I might be asking for
too much but maybe someone has seen something like that before. It would
definetly save us developers a lot of frustration if we knew ahead of time
that method xyz() is not supported when using the bridge.

Again, I appreciate your time and effort.

Greg Sliker

"Gregory M. Sliker" <gsl...@lightstream.net> wrote in message
news:3G5K5.917$d3.49...@news.axxsys.net...

Joseph Weinstein

unread,
Nov 2, 2000, 4:06:50 PM11/2/00
to Gregory M. Sliker
Hi.
The jdbc-odbc driver is broken. The code is fine.
You can get around this by some home-cooked batching
that will be as fast or faster than JDBC 2.0 batches:

Statement stmt = conn.createStatement();
conn.setAutoCommit(false);

String myBatch = "";

for (int idx = 0; idx < 5; idx++)
{

myBatch += "insert into batchTest( id, text) values( "
+ idx + ", "
+ "IDX=" + idx
+ ") " // keep space after parenthesis!
);
}

try {
stmt.executeUpdate(myBatch);
conn.commit();
}
catch (Exception e)
{
conn.rollback();
}

conn.setAutoCommit(true);

Let me know if this helps,
Joe Weinstein at BEA

--

PS: Folks: BEA WebLogic is in S.F. with both entry and advanced positions for
people who want to work with Java and E-Commerce infrastructure products. Send
resumes to j...@bea.com
--------------------------------------------------------------------------------
The Weblogic Application Server from BEA
JavaWorld Editor's Choice Award: Best Web Application Server
Java Developer's Journal Editor's Choice Award: Best Web Application Server
Crossroads A-List Award: Rapid Application Development Tools for Java
Intelligent Enterprise RealWare: Best Application Using a Component Architecture
http://www.bea.com/press/awards_weblogic.html

Joseph Weinstein

unread,
Nov 2, 2000, 7:31:01 PM11/2/00
to Joseph Weinstein
I just typed the code in and now see the extra ')'.
The compiler-friendly code :-) is:

Statement stmt = conn.createStatement();
conn.setAutoCommit(false);

String myBatch = "";

for (int idx = 0; idx < 5; idx++)
{
myBatch += "insert into batchTest( id, text) values( "
+ idx + ", "
+ "IDX=" + idx
+ ") "; // keep space after parenthesis!
}

try {


stmt.executeUpdate(myBatch);
conn.commit();
}
catch (Exception e)
{
conn.rollback();
}

conn.setAutoCommit(true);

AV

unread,
Nov 2, 2000, 10:56:41 PM11/2/00
to
thanks for an idea... :-)

AlexV

"Joseph Weinstein" <j...@weblogic.com> wrote in message
news:3A020745...@weblogic.com...

Reply all
Reply to author
Forward
0 new messages