下面这段话有什么问题,输入已有的用户名会执行“该用户名已存在”,但是输入新的用户名显示注册成功但是数据库里没有新的记录,应该是赋值语句有问题,请问insert语句哪里错了呢
String username=request.getParameter("r_user");
String password=request.getParameter("r_password");
sql=conn.createStatement();
rs=sql.executeQuery("select * from user where username='"+username+"'");
if(!rs.next()){String updateCondition="insert into user(username,password)values('"+username+"','"+password+"')";
out.print("注册成功!");response.setHeader("refresh","2;URL=index.jsp");}else{out.print("该用户名已存在");response.setHeader("refresh", "3;URL=reg2.jsp");}
}

jsp中sql的insert语句问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- ooooooooooooooooooMG 2014-12-22 02:46关注
如果存在,你只是写了一个sql语句,并没有执行操作update啊,当然不会insert到数据了
而且SQL语句使用拼接的方式会有SQL注入漏洞的,建议改成动态传参的方式本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报