Explain how to do batch updates using CallableStatement interface.
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);
}