public int deleteGoodsOne(String goodid,int status) {
int i = 0;
String sql = "";
if(status == 1 || status == 2)
{
sql = "update goods set status = 0 where goodid = ?";
//这里想增加update record set status = 0 where goodid = ?
}else{
sql = "update goods set status = 1 where goodid = ?";
//这里想增加update record set status = 0 where goodid = ?
}
conn = db.getConn();
try {
ps = conn.prepareStatement(sql);
ps.setString(1,goodid);
i=ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
db.closeDB(conn);
}
return i;
}
请问怎么实现?
JAVA用批处理怎么执行多条SQL语句
答案:2 悬赏:30 手机版
解决时间 2021-12-17 06:56
- 提问者网友:浪子未归
- 2021-12-16 16:27
最佳答案
- 五星知识达人网友:甜甜的少女心
- 2021-12-16 16:48
public int deleteGoodsOne(String goodid,int status) {
int i = 0;
String sql = "";
conn = db.getConn();
try {
if(status == 1 || status == 2) {
sql = "update goods set status = 0 where goodid = ?";
//这里想增加update record set status = 0 where goodid = ?
}else{
sql = "update goods set status = 1 where goodid = ?";
//这里想增加update record set status = 0 where goodid = ?
}
// 第一次执行逻辑判断sql
ps = conn.prepareStatement(sql);
ps.setString(1,goodid);
i=ps.executeUpdate();
//第二次执行更新record表的sql
sql = 'update record set status = 0 where goodid = ?';
ps = conn.prepareStatement(sql);
ps.setString(1,goodid);
i=ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
db.closeDB(conn);
}
return i;
}
int i = 0;
String sql = "";
conn = db.getConn();
try {
if(status == 1 || status == 2) {
sql = "update goods set status = 0 where goodid = ?";
//这里想增加update record set status = 0 where goodid = ?
}else{
sql = "update goods set status = 1 where goodid = ?";
//这里想增加update record set status = 0 where goodid = ?
}
// 第一次执行逻辑判断sql
ps = conn.prepareStatement(sql);
ps.setString(1,goodid);
i=ps.executeUpdate();
//第二次执行更新record表的sql
sql = 'update record set status = 0 where goodid = ?';
ps = conn.prepareStatement(sql);
ps.setString(1,goodid);
i=ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
db.closeDB(conn);
}
return i;
}
全部回答
- 1楼网友:久拥深怀
- 2021-12-16 17:18
使用preparedstatement的addbatch()方法添加批量sql执行,然后用executebatch()来批量执行add进去的sql
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯