Here's how I use it:
Lets assume insertObjects is an array of InsertObject -s that we want to
persist
try
{
sqlMapClient.startTransaction();
sqlMapClient.startBatch();
for (InsertObject insertObject : insertObjects)
{
sqlMapClient.insert("XMLFile.insertStatement",
insertObject);
}
sqlMapClient.executeBatch();
}
catch (SQLException ex)
{
// log error etc. but note no explicit rollback needed
}
finally
{
try
{
sqlMapClient.endTransaction();
}
catch (SQLException ex)
{
\\ wow something's very very wrong
}
}
Please not that if the array is quite large (more than couple of hundred
objects) you'd better use startBatch-executeBatch-commits not for entire
loop, but slice it to say every 100. Of course these numbers are usually
determined by simply trying several values in the range ~20-1000