Hello,
this is a known bug, which will be fixed in the next version of JDBC-driver.
Thank you for reporting the bug.

Regards,
Marco
----------------------------------------------
Marco PASKAMP
SAP DB, SAP Labs Berlin

> -----Original Message-----
> From: Matthias Bild [mailto:[EMAIL PROTECTED]]
> Sent: Donnerstag, 28. Februar 2002 12:07
> To: [EMAIL PROTECTED]
> Subject: JDBC driver BatchUpdateException.getUpdateCounts() problem
> 
> 
> Hi all,
> 
> I think there is a problem with the jdbc 
> BatchUpdateException.getUpdateCounts() function.
> If a statement in the batch update fails, the sapdb driver 
> continues with 
> the execution
> of the remaining statement. That is ok with the spec. The 
> executeBatch() 
> function throws
> a BatchUpdateException if something goes wrong, and the 
> BatchUpdateException
> provides the getUpdateCounts() method to find out what went wrong.
> 
> The jdk1.3 getUpdateCounts() javadoc states that each entry in the 
> returning int array is one
> of the following:
> 1. an update count
> 2. -2 to indicate that the command executed successfully but 
> the number of 
> rows affected is unknown
> 3. -3 to indicate that the command failed to execute successfully
> 
> However, the sapdb driver returns -1 for failed statements. This is
> dangerous because the "-2" indicates a successful execution and
> therefore we cannot assume that every negative value is a failed
> statement.
> 
> The code snippets demonstrate the problem:
> 
> 
> 
> try
> {
>       conn.setAutoCommit( false );
>       
>       statement = conn.createStatement();
>       statement.addBatch( "INSERT INTO TEST (ID, NAME) VALUES 
> (1, 'Test 1')" );
>       statement.addBatch( "INSERT INTO TEST (ID, NAME) VALUES 
> (2, 'Test 2')" );
>       statement.addBatch( "INSERT INTO TEST (ID, NAME)xxxxx 
> VALUES (3, 'Test 
> 3')" ); // wrong sql statement
>       statement.addBatch( "INSERT INTO TEST (ID, NAME) VALUES 
> (4, 'Test 4')" );                     
>       int insertCount[] = statement.executeBatch();
>       for (int i = 0; i< insertCount.length; i++)
>               System.out.println("insert count ["+ i + "] = " 
> + insertCount[i]);
>               
>       conn.commit();
> }
> catch( BatchUpdateException x )
> {
>       int insertCount[] = x.getUpdateCounts();
>       for (int i = 0; i< insertCount.length; i++)
>               System.out.println("insert count ["+ i + "] = " 
> + insertCount[i]);
>       
>       conn.commit();
> }
> 
> The output is:
> insert count [0] = 1
> insert count [1] = 1
> insert count [2] = -1
> insert count [3] = 1
> 
> 
> Greetings Matthias
> --
> [EMAIL PROTECTED]
> 
> _______________________________________________
> sapdb.general mailing list
> [EMAIL PROTECTED]
> http://listserv.sap.com/mailman/listinfo/sapdb.general
> 
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general

Reply via email to