• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Batch update problem in Spring Prepared statement

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic