62,614
社区成员
发帖
与我相关
我的任务
分享
Connection conn = DBUtilc3p0.getInstance().getConnection();
PreparedStatement ps = null;
try {
conn.setAutoCommit(false);
String sql="update user set money=money-? where name=? "
+"update user set money=money+? where name=? "
+"update temp set count=count+1 where name=? ";
ps = conn.prepareStatement(sql);
ps.setInt(1, 100);
ps.setString(2, "张三");
ps.setInt(3, 100);
ps.setString(4, "李四");
ps.setString(5, "张三");
ps.executeUpdate();
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
} finally {
closeAll(conn, ps, null);
}
Statement ps=conn.createStatement();
ps.addBatch("update user set money=money-100 where name='张三'");
ps.addBatch("update user set money=money+100 where name='李四'");
ps.addBatch("update temp set count=count+1 where name='张三'");
ps.executeBatch();
PreparedStatement ps=conn.prepareStatement("insert into temp values(?)");
ps.setInt(1, 100);
ps.addBatch();
ps.setInt(1, 200);
ps.addBatch();
ps.executeBatch();
String sql = delete from annex where annexcode = ?;
String[] codes = {'aa','bb','cc'}
pst = cn.prepareStatement(sql);
for(int i=0;i<codes.length;i++){
pst.setString(1, codes[i]);
pst.addBatch();
}
pst.excuteBatch();