public void test(){
try {
con.setAutoCommit(false);
PreparedStatement pst = con.prepareStatement("insert into t_teacher (name) values ('dddd')");
System.out.println(con.getAutoCommit());
pst.executeUpdate();
pst.executeUpdate("update t_teacher set age=11");
con.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
try {
con.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}con 是一个connection的对象.这样写有错吗?
为什么不是一个事务呀?
try {
con.setAutoCommit(false);
PreparedStatement pst = con.prepareStatement("insert into t_teacher (name) values ('dddd')");
System.out.println(con.getAutoCommit());
pst.executeUpdate();
pst.executeUpdate("update t_teacher set age=11");
con.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
try {
con.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}con 是一个connection的对象.这样写有错吗?
为什么不是一个事务呀?
楼主【andongoop】截止到2008-06-24 14:25:07的历史汇总数据(不包括此帖):
发帖数:6 发帖分:80
结贴数:1 结贴分:10
未结数:5 未结分:70
结贴率:16.67 % 结分率:12.50 %