为什么sql的语句不执行??????

qianzongli 2007-07-17 01:20:20
String action=Req.getPara(request,"action");
String [] result = request.getParameterValues("test");
String sql="";
int errcode;
int j=0;
if(action.equals("update")){
int count=Integer.parseInt(Req.getPara(request,"count"));
String idList="";
//System.out.print("12313316554");
for(int i=0;i<result.length;i++){
j=Integer.parseInt(result[i]);

sql="update tbtool_ques_option set clicks=clicks+1 where id='j'";
errcode=dao.conExec(sql);
...全文
286 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
KingNE 2007-07-17
  • 打赏
  • 举报
回复
up
wfr0701 2007-07-17
  • 打赏
  • 举报
回复
对1. 2. 5. 是什么?的回答:
其实1. 2. 5就是你的更新条件J的值;也就是说叫你不要在循环内执行SQL,方法如下:
String sql="update tbtool_ques_option set clicks=clicks+1 where id in (";
for(int i=0;i<result.length;i++){
j=Integer.parseInt(result[i]);
if(i==0){
sql +=j;
}else{
sql+=","+j;
}
if(i==result.length-1){
sql+=")";
}
}
errcode=dao.conExec(sql);
worilo 2007-07-17
  • 打赏
  • 举报
回复
sql="update tbtool_ques_option set clicks=clicks+1 where id='j'"
字符转义啊
qianzongli 2007-07-17
  • 打赏
  • 举报
回复
1. 2. 5. 是什么?
qianzongli 2007-07-17
  • 打赏
  • 举报
回复
谢谢啊!!大哥.怎么给你分啊
iisbocai 2007-07-17
  • 打赏
  • 举报
回复
另外提几个建议。
1)你应该判断action,results是否为null,否则会出bug。你不能期望用户按照你想的进行输入。
2)你在for循环中执行了多次update数据库操作,这是低效率的。你可以将它组合为一个sql语句,形式如下update tbtool_ques_option set clicks=clicks+1 where id in (1,2,5).这样效率会高出很多。

iisbocai 2007-07-17
  • 打赏
  • 举报
回复
sql="update tbtool_ques_option set clicks=clicks+1 where id='j'";
这一行是不是你的原程序?
如果是,那显然是不对。
1)如果id是字符型,应该为sql="update tbtool_ques_option set clicks=clicks+1 where id='"+j+"'";
2)如果id是数字型,应该为sql="update tbtool_ques_option set clicks=clicks+1 where id="+j;

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧