aspose file tools*
The moose likes JDBC and the fly likes Exception in Batch Update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception in Batch Update" Watch "Exception in Batch Update" New topic
Author

Exception in Batch Update

nivas khan
Greenhorn

Joined: Aug 08, 2001
Posts: 7
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Aug 08, 2001
Posts: 7
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

Joined: Jul 09, 2001
Posts: 1879

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in Batch Update