All data that you pass in the SQL statements must be passed as literals. None of the SQL statements can return ResultSet objects.
To initiate a batch update, your application calls this version of the updateMany() method:
int[] updateMany(String... heterogeneousBatchSQL)
The parameter heterogeneousBatchSQL can be a list of individual SQL statements or an array of String objects that contain SQL statements. The following two examples show the different methods of passing the SQL statements:
String insertDept = "insert into dept values("+dept.no+",'"+dept.name+"')";
String insertEmp = "insert into emp values("+emp.id+",'"+emp.name+"','"+emp.ssn+"',"+emp.dept_no+")";
String insertEmpProj = "insert into emp_proj values("+emp.id+","+dept.no+")";
int[] updateCounts = myData.updateMany (insertDept, insertEmp, insertEmpProj);
String[] sqlArray = new String[3];
sqlArray[0] = insertDept;
sqlArray[1] = insertEmp;
sqlArray[2] = insertEmpProj;
int[] updateCounts = myData.updateMany (sqlArray);
The method returns an integer array that has the same number of elements as SQL statements that you supplied. This array contains the same information that the Statement.executeBatch() method in JDBC returns.
If you are using annotated methods and want to call the updateMany() method, see Extending user-defined classes from generated implementation classes. You can call the updateMany() method like this:
int[] updateCounts = updateInf.updateMany (hetrogeneousBatchSQL);
updateInf.commit ();
If one or more SQLExceptions are returned from the JDBC driver, they are wrapped within an UpdateManyException.
If the JDBC driver or database returns an SQLException, the updateMany() method throws an com.ibm.pdq.runtime.exception.UpdateManyException. You can retrieve an array that contains the update count from the by calling the UpdateManyException.getUpdateCounts() method.
You can retrieve the original SQLException (or multiple SQLExceptions) by calling the UpdateManyException.getCause() method. Because the JDBC driver can return multiple SQLExceptions, these exceptions are chained together. You can retrieve them by calling the SQLException.getNextException() method, which returns an SQLException until there are no more SQLExceptions, at which point a null is returned.