Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in Batch Update

 
nivas khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();}
}
}
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
nivas khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic