Connection conn = DataSourceUtils.getConnection(getDataSource());//申请连接
{
/*T1*/
String insertUser = "insert into TB_User values(?,'默罕默德','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
System.out.println("insert new User ‘默罕默德’...");
new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
Thread.sleep(1000);
}
{
/*T2*/
System.out.println("begin T2!");
this.executeTransactional();
System.out.println("rollBack T2!");
Thread.sleep(1000);
}
{ /*T1*/
String insertUser = "insert into TB_User values(?,'赵飞燕','muhammad','123','muhammad@hasor.net','2011-06-08 20:08:08');";
System.out.println("insert new User ‘赵飞燕’...");
new JdbcTemplate(conn).update(insertUser, newID());//执行插入语句
Thread.sleep(1000);
}
DataSourceUtils.releaseConnection(conn, getDataSource());//释放连接
}