Hi
we want to know that how to do batch updates using CallableStatement interface.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted May 14, 2012, 1:53 PM
Batch update is the ability to add more than one statement at once.
CallableStatement.executeBatch() method is used to execute the batch of statements. This will return integer number of records updated, if it returns other than that BatchUpdateException will occur.
For Example:
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:students");
Callable Statement c= con.prepareCall("{Call insert_data(?,?)});
//set input parameters
c.setInt(1,10);
c.setString(2,"ABC");
c.addBatch();
c.setInt(1,11);
c.setString(2,"DEF");
c.addBatch();
int [] updateCounts = c.executeBatch();
}
catch(BatchUpdateException bu)
{
System.out.println(bu);
}
catch(SQLException e)
{
System.out.println(e);
}
catch(ClassNotFoundException e1)
{
System.out.println(e1);
}
}
}
Thanks