JAVA用批处理怎么执行多条SQL语句
publicintdeleteGoodsOne(Stringgoodid,intstatus){inti=0;Stringsql="";if(status==1||sta...
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;
}
请问怎么实现? 展开
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;
}
请问怎么实现? 展开
展开全部
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;
}
追问
还是不行啊,能在我的代码基础上改吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询