JDBC中事務的問題之二

X.Underset發表於2006-03-03
public void Login()throws Exception
{

User user = new User();
Password password = new Password();

MySQL mysql = new MySQL();

try
{
mysql.getConnection().setAutoCommit(false);

password.Insert(引數1);
user.Insert(引數2);

mysql.getConnection().commit();

}catch(Exception e)
{
mysql.getConnection().rollback();
}finally{
mysql.close();
}
其中的password物件和user物件的insert分別做的是自己的資料插入操作
現在這個事務能起到原來的作用嗎

相關文章