Forums Register Login

Exception in Batch Update

+Pie Number of slices to send: Send
Dear All,
I am trying to execute a batch process which calls a procedure for insertion of records into database.My database is Microsoft SQL 7.0 .
A Negative Array Size Exception comes while executing the program.
I have tried modifying the code but everytime the exception pops up....
Can someone help me with the code.
Thanks in advance......
Nivas

Here is my code

import java.sql.*;
public class Batch_Update_Test
{
public static void main(String args[])
{
Connection oConn4=null;
CallableStatement stmt = null;
String strsql;
int LngBatchCount=0;
strsql = "{ call Test ( ? , ? ) }";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
oConn4 = DriverManager.getConnection("jdbc dbc:filedsn","username","password");
oConn4.setAutoCommit(false);
stmt= oConn4.prepareCall(strsql);
}catch(Exception e){System.out.println("Exception In connection :- ");e.printStackTrace();}
for (int i=1;i<=100;i++)
{
LngBatchCount++;
try
{
if (LngBatchCount>1) {stmt.addBatch();System.out.println("Batch Added");}
stmt.setInt(1,i);
stmt.setString(2,(("CR" + i).toString()));
System.out.println("LngBatchCount :- " + LngBatchCount);
}catch(Exception e){System.out.println("Exception In setting parameters :- ");e.printStackTrace();}
if(LngBatchCount == 10)
{
LngBatchCount = 0;
try
{
int[] insertCount = stmt.executeBatch();
//stmt.executeBatch();
oConn4.commit();
stmt.clearBatch();
System.out.println("Executed Records :- " + insertCount.length);
}catch(Exception e){System.out.println("Exception In Executing Procedure :- " + i );e.printStackTrace();}
}
}
try
{
oConn4.setAutoCommit(true);
stmt.close();oConn4.close();
stmt=null;oConn4=null;
}catch(Exception e){System.out.println("Closing Connection:- ");e.printStackTrace();}
}
}
+Pie Number of slices to send: Send
does this exception occur if you changed int[] insertCount = stmt.executeBatch(); to just stmt.executeBatch(); ? I'm not sure if the ODBC bridge implements the method properly.
Jamie
+Pie Number of slices to send: Send
Hi,
Jamie ...
I get the same exception when i
change int[] insertCount = stmt.executeBatch(); to just stmt.executeBatch();
What Could be the problem...
Please Help..
+Pie Number of slices to send: Send
Honestly, I haven't seen an answer to this problem yet. I therefore assume it is a bug in the jdbc-odbc to MSSQL Server drivers. Can you switch drivers to the new Microsoft type 4 drivers?
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1418 times.
Similar Threads
How to rollback multiple prepared statements
error during batch update
Batch update in EJB
Batch Insert
setAutoCommit(false) not working
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:45:08.