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 = 1 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 = 1 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;
}
请问怎么实现? 展开
1个回答
2015-12-08
展开全部
使用PreparedStatement的addBatch()方法添加批量sql执行,然后用executeBatch()来批量执行add进去的sql
追问
能在我的基础上改一下吗?我自己改完后不能用,也没有报错信息~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |