要把数据插入到多张表?
我有个问题:我要把一条数据插入3张表中,如何控制插入出错时全部回滚,我现在的代码是这样的:
PreparedStatement pstmt = con.prepareStatement(
"insert into Xz_jbxxb(xz_id,xx_id,xk_id,xz_cxrq,dc_id,xz_cxc,xz_zt) values (?,?,?,?,?,?,?) ");
pstmt.setString(1, (String) listxh.get(i));
pstmt.setString(2, (String) listzyxxx.get(1));
pstmt.setString(3, (String) listzyxxx.get(2));
pstmt.setString(4, (String) listzyxxx.get(3));
pstmt.setString(5, (String) listzyxxx.get(4));
pstmt.setString(6, (String) listzyxxx.get(5));
pstmt.setString(7, "ZYX ");
pstmt.execute();
pstmt.clearParameters();
pstmt = con.prepareStatement(
"insert into Xz_zyx(xz_id,xz_zt,xz_cbj,xz_dcf,xz_qtfy,xz_zjj,xz_czjg,dt_id) values (?,?,?,?,?,?,?,?) ");
pstmt.setString(1, (String) listxh.get(i));
pstmt.setString(2, "ZYX ");
pstmt.setFloat(3, Float.parseFloat((String)listzyxxx.get(6)));
pstmt.setFloat(4, Float.parseFloat((String) listzyxxx.get(8)));
pstmt.setFloat(5, Float.parseFloat((String) listzyxxx.get(9)));
pstmt.setFloat(6, Float.parseFloat((String)