com.mysql.jdbc.exceptions.MySQLSyntaxErrorException?

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() ;

}

 %>

 


忍帅锅
浏览 3739回答 1
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+")";      这样写就通过了!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
MySQL