ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sven Boden <list...@pandora.be>
Subject Re: executeBatch not returning int of records updated.
Date Tue, 20 Jun 2006 19:29:31 GMT

If you're using Oracle it's a known problem, and not in iBATIS. The JDBC 
spec lets vendors skip certain parts, and Oracle decided to skip the 
part in their driver where they return the number of rows updated by a 
prepared statement.

Regards,
Sven

jaybytez wrote:

>I have a method that loops through a list and tries to commit every 100
>records for batch updates/inserts/deletes.  When I run the
>sqlMap.executeBath, the return value of the int is 0.  Is there a reason
>this is occurring?  Am I doing the batch incorrectly?  It is at the line
>where the code is commitBatchUpdated = sqlMap.executeBatch();
>
>I do a test against the total records update so that I know if no records
>were updated or if some of the records failed so that the whole batch did
>not complete.
>
>    /**
>     * @param argument param
>     * @param sqlMap param
>     * @param methodName param
>     * @param batchType param
>     *
>     * @return returned
>     */
>    private Object batch(Object argument, SqlMapClient sqlMap, String
>methodName) {
>        int commitSize = 100;
>        boolean commitBatch = false;
>        int totalRecordsUpdated = 0;
>        int commitBatchUpdated = 0;
>
>        try {
>            List list = (List)argument;
>            sqlMap.startTransaction();
>            sqlMap.startBatch();
>            
>            for(int i = 0; i < list.size(); i++) {
>
>                sqlMap.insert(methodName, list.get(i));
>
>                if(i == (commitSize - 1)) {
>                    commitBatch = true;
>                }
>                else if(i == (list.size() - 1)) {
>                    commitBatch = true;
>                }
>
>                if(commitBatch) {
>                    commitBatchUpdated = sqlMap.executeBatch();
>                    totalRecordsUpdated = totalRecordsUpdated +
>commitBatchUpdated;
>                    commitBatch = false;
>                }
>            }
>
>            sqlMap.commitTransaction();
>            
>            if(totalRecordsUpdated == 0) {
>                throw new DataAccessException("No records were modified by
>the batch statement. " + methodName);
>            }
>            if(totalRecordsUpdated != list.size()) {
>                throw new DataAccessException("Not all of the records were
>successfully updated/inserted/deleted in batch mode. " + methodName);
>            }
>        }
>        catch(SQLException e) {
>            exceptionConverter.rethrow(methodName, e);
>        }
>        finally {
>            try {
>                sqlMap.endTransaction();
>            }
>            catch (SQLException e) {
>                exceptionConverter.rethrow(methodName, e);
>            }
>        }
>
>        return new Integer(totalRecordsUpdated);
>    }
>
>Thanks,
>
>Jay Blanton
>--
>View this message in context: http://www.nabble.com/executeBatch-not-returning-int-of-records-updated.-t1819686.html#a4961604
>Sent from the iBATIS - User - Java forum at Nabble.com.
>
>
>
>  
>


Mime
View raw message