request.setCharacterEncoding("UTF-8");String nickname = request.getParameter("nickname");
String password = request.getParameter("password");
String email = request.getParameter("email");
System.out.print(nickname +  password + email);
Connection conn = DB.getConn();
String sql = "insert into logininfo values (null,?,?,?,1)";
PreparedStatement pstmt = DB.prepareStmt(conn,sql);
pstmt.setString(1,nickname);
pstmt.setString(2,password);
pstmt.setString(3,email);
System.out.println(sql);
pstmt.executeUpdate(sql);
DB.close(pstmt);
DB.close(conn);response.sendRedirect("index.jsp");
DB.java
package com.job51.www;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class DB {
public static Connection getConn() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/job", "root", "baixingong");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
System.out.print("加载mysql数据库驱动出错");
e.printStackTrace();
}
return conn;
} public static Statement createStmt(Connection conn) {
Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return stmt;
} public static ResultSet executeQuery(Statement stmt, String sql) {
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}

public static PreparedStatement prepareStmt(Connection conn,String sql){
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return pstmt;
} public static void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn = null;
}
} public static void close(Statement stmt) {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stmt = null;
}
} public static void close(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
rs = null;
}
}
}JSP

解决方案 »

  1.   

    type Exception reportmessage javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.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 '?,?,?,1)' at line 1description The server encountered an internal error that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.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 '?,?,?,1)' at line 1
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.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 '?,?,?,1)' at line 1
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
    org.apache.jsp.registerok_jsp._jspService(registerok_jsp.java:95)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause com.mysql.jdbc.exceptions.jdbc4.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 '?,?,?,1)' at line 1
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    com.mysql.jdbc.Util.getInstance(Util.java:386)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2809)
    com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
    com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
    org.apache.jsp.registerok_jsp._jspService(registerok_jsp.java:71)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.36 logs.
      

  2.   

    看不太懂,貌似是SQL语句出现了问题,但是语法貌似没有错误啊
      

  3.   

    你这个 sql已经传入了 PreparedStatement pstmt = DB.prepareStmt(conn,sql);
     你这个sql 还要的干嘛? pstmt.executeUpdate(sql);
      

  4.   

    将你的sql改成insert into logininfo(nickname,password,email) values (?,?,?,1); 
      

  5.   

    给一下表结构最好了,问题应该出现在 sql语句上 insert into logininfo values (null,?,?,?,1),
    最好把需要的表字段放在表名后面,如 insert into logininfo(id,nickname,password,email,gendex) values (null,?,?,?,1)
      

  6.   

    问题1:String nickname = (String)request.getParameter("nickname"); 
    问题2: String sql = "insert into logininfo values (null,?,?,?,1)"; 
    你这个Sql语句,null代表什么啊,一般第一个是id吧 可以再数据库中设置自增,你自己试试将问号都替换了去数据库执行以下语句看看能不能对这是插入语句pstmt.executeUpdate(sql);  这是更新时候用的啊,这个都不知道吗?
    PreparedStatement pstmt = DB.prepareStmt(conn,sql); 
    pstmt.setString(1,nickname);
     pstmt.setString(2,password); 
    pstmt.setString(3,email); 
    System.out.println(sql); 
    pstmt.executeUpdate(sql);修改成pstmt.execute()前面DB.prepareStmt(conn,sql); 这个地方已经有了
     DB.close(pstmt); DB.close(conn); 
      

  7.   

    check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?,1)' at line 1
    把你的sql打印出来看看是不是语法错了呀