com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?,?,?,?,?,?,?,?)' at line 1利用jsp写登录界面时出现上面报错,是什么原因呢?<%try{ conn = DBHelper.getConnection(); String sql = "insert into userinfo (yid,username,password,sex,age,addr,tel,sid,email,balance) values (?,?,?,?,?,?,?,?,?,?)";//插入语句,”?”表示接受参数值 pstmt = conn.prepareStatement(sql); //给sql语句中的变量赋值 pstmt.setString(1, request.getParameter("yid")); pstmt.setString(2, request.getParameter("username")); pstmt.setString(3, request.getParameter("password")); pstmt.setString(4, request.getParameter("sex")); pstmt.setString(5, request.getParameter("age")); pstmt.setString(6, request.getParameter("address")); pstmt.setString(7, request.getParameter("tel")); pstmt.setString(8, request.getParameter("id")); pstmt.setString(9, request.getParameter("email")); pstmt.setString(10, request.getParameter("balance")); int updatenumber = pstmt.executeUpdate(sql); if(updatenumber!=0) { request.getRequestDispatcher("login_success.jsp").forward(request, response); } else { response.sendRedirect("login_failure.jsp"); } }catch(Exception e) { e.printStackTrace() ;} %>
1 回答
忍帅锅
TA贡献2条经验 获得超1个赞
已解决:
String sql ="insert into userinfo(yid,username,password,sex,age,addr,tel,email,sid,balance) values("+yid+","+username+","+password+","+sex+","+age+","+addr+","+tel+","+email+","+sid+","+balance+")";
这样写就通过了!
添加回答
举报
0/150
提交
取消