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




































































































































































































































程序的運(yùn)行結(jié)果是,由于在insert方法中的查詢語句出錯(cuò),會(huì)引起之前的insert語句效果被撤銷。你也可以把查詢語句先設(shè)置正確,看看效果。