File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Batch update problem in Spring Prepared statement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Reply Bookmark "Batch update problem in Spring Prepared statement" Watch "Batch update problem in Spring Prepared statement" New topic
Author

Batch update problem in Spring Prepared statement

Mothea Anil Kumar
Greenhorn

Joined: Aug 01, 2005
Posts: 22
Hi,

I am using struts+hibernate+spring technologies in my project. I'm using DB2 as data base. I'm having the below problem in using batchUpdate() method for one of the delete method. Actually this delete method has to delete around 40 thousand of records at atime. So i'm breaking up the count and deleting for every 1000 rows using the below spring,

private void deleteFromMainTablesExc(String deleteQuery,
StringBuffer idsList) throws SQLException {
try{
log.info ("idsList:"+ idsList);
StringTokenizer strToken = new StringTokenizer(idsList.toString(),",");
final List idsListTemp = new ArrayList();
while (strToken.hasMoreElements()){
idsListTemp.add((String)strToken.nextElement());
}
jdbc.batchUpdate(deleteQuery,new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setInt(1, Integer.parseInt((String)idsListTemp.get(i)));

}
public int getBatchSize() {
return idsListTemp.size();
}
});
log.info ("deleteFromMainTablesExc:"+idsList);
}catch(Exception e){
System.out.println("Exception is :" +e);
e.printStackTrace();
}
}

My problem is for one of the data set it worked fine without having any issues. But it's not working for another dataset.
Is there any max limit for batch update statement? Or anything needs to be fix from code point of view?

Below error i'm getting while executing my program,

org.springframework.jdbc.UncategorizedSQLException: (executing PreparedStatementCallback [org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator@19a0feb]): encountered SQLException [Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.]; nested exception is com.ibm.db2.jcc.c.ud: Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.
com.ibm.db2.jcc.c.ud: Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.
at com.ibm.db2.jcc.c.i.a(i.java:358)
at com.ibm.db2.jcc.c.zc.b(zc.java:2877)
at com.ibm.db2.jcc.c.zc.a(zc.java:2666)
at com.ibm.db2.jcc.c.zc.executeBatch(zc.java:2478)
at com.ibm.db2.jcc.c.zc.executeBatch(zc.java:1365)
at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:743)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:450)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:469)
at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:734)
at com.kroger.accounting.ad.jdbc.DBPurgeService_Production.deleteFromMainTablesExc(DBPurgeService_Production.java:319)
at com.kroger.accounting.ad.jdbc.DBPurgeService_Production.deleteFromMainTables(DBPurgeService_Production.java:351)
at com.kroger.accounting.ad.jdbc.DBPurgeService_Production.removeDataFromMainTable(DBPurgeService_Production.java:490)
at com.kroger.accounting.ad.jdbc.DBPurgeService_Production.purge(DBPurgeService_Production.java:266)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy5.purge(Unknown Source)
at com.kroger.accounting.ad.process.PurgeProcess.<init>(PurgeProcess.java:28)
at com.kroger.accounting.ad.process.PurgeProcess.main(PurgeProcess.java:48)
Exception in thread "main" java.lang.RuntimeException: (executing PreparedStatementCallback [org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator@19a0feb]): encountered SQLException [Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.]; nested exception is com.ibm.db2.jcc.c.ud: Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.
at com.kroger.accounting.ad.process.PurgeProcess.<init>(PurgeProcess.java:38)
at com.kroger.accounting.ad.process.PurgeProcess.main(PurgeProcess.java:48)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.
 
I agree. Here's the link: jrebel
 
subject: Batch update problem in Spring Prepared statement
 
Similar Threads
getNextException SQLGrammarException
DB2 duplicate rows error code
MySQL Problem !!!
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException:
Error during large batch insertion for preparedstatement (395 parameters)