public void runStatementsUsingSetUserConnection()
{
SqlMapClient sqlMapClient =SqlMapClientConfig.getSqlMapClient();
Connection conn = null;
SqlMapSession session = null;
try {
conn = dataSource.getConnection();
conn.setAutoCommit(false);
session = sqlMapClient.openSession(conn);
Person p =(Person)session.queryForObject("getPerson",new Integer(9));
p.setLastName("Smith");
session.update("updatePerson", p);
Department d =(Department)session.queryForObject("getDept", new Integer(3));
p.setDepartment(d);
session.update("updatePersonDept", p);
conn.commit();
} finally {
if (session != null) session.close();
if (conn != null) conn.close();
}
}
Custom transaction control with openSession
最新推荐文章于 2021-07-26 10:45:38 发布