public boolean addSeatInfo(TSeatInfo ts,String OrderDetailID)throws Exception { boolean b=false; Connection conn=null; PreparedStatement ps = null; Statement st = null; ResultSet rs=null; try { conn = DBMgr.getInstance().getConn(); conn.setAutoCommit(false); String sql="insert into t_seat_info(seq_seat_info_id,Creator,CreateTime,SeatDesc,WhichSell,WhoSell,WhenSell,Num)" +"values(seq_seat_info.nextval,?,sysdate,?,?,?,sysdate,?)"; ps = conn.prepareStatement(sql); ps.setString(1,ts.getCreator()); ps.setString(2,ts.getSeatDesc()); ps.setString(3,ts.getWhichSell()); ps.setString(4,ts.getWhoSell()); ps.setFloat(5,ts.getNum()); ps.executeUpdate(); st = conn.createStatement(); String key=""; rs= st.executeQuery("select seq_seat_info.currval from dual"); if(rs.next()) { key=rs.getString(1); } sql="update t_order_detail set seq_seat_info_id=? where seq_order_detail_id=?"; ps = conn.prepareStatement(sql); ps.setString(1,key); ps.setString(2,OrderDetailID); ps.executeUpdate(); conn.commit(); b=true; } catch(Exception e) { conn.rollback(); e.printStackTrace(); } finally { if(ps!=null) { ps.close(); } if(st!=null) { st.close(); } if(rs!=null) { rs.close(); } conn.setAutoCommit(true); DBMgr.closeCon(conn); } return b; }
java中的事务处理原则_Java中事务处理方法
最新推荐文章于 2024-07-20 15:22:38 发布