1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
try {
SqlMapSession session = sqlMap.openSession()
session.startTransaction()
Employee emp2 = new Employee();
// ...set emp2 data
Integer generatedKey = (Integer) session.insert ("insertEmployee", emp2);
emp2.setFavouriteColour ("green");
session.update("updateEmployee", emp2);
session.commitTransaction();
} finally {
try {
session.endTransaction();
} finally {
session.close();
}
// Generally your session scope would be in a wider context and therefore the
// ugly nested finally block above would not be there. Realize that sessions
// MUST be closed if explicitly opened (via openSession()).
} |
Partager