Hi
we want to know that how to do batch updates using CallableStatement interface.
Explain how to do batch updates using CallableStatement interface?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted May 14, 2012, 9:53 AM EDT
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