首先,在MySQL中建立一個表myuser。注意要讓MySQL支持事務,要選擇InnoDB類型的表。
Create table myuser(
?id int (11) not null auto_increment primary key,
name varchar(100) not null default '',
age int
)type=InnoDB;
這里有個實體類user.java:




































































































































































































































程序的運行結果是,由于在insert方法中的查詢語句出錯,會引起之前的insert語句效果被撤銷。你也可以把查詢語句先設置正確,看看效果。