Java 如何解决MySQL语法错误异常?

Java 如何解决MySQL语法错误异常?,java,mysql,Java,Mysql,我正在尝试从wampserver mysql数据库将数据插入我的jtable。我不断收到这个特定错误com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:Erreur de syntaxe près de')la ligne 1. 这是我的密码 public Boolean add( String Registration,String Departure, String capacity, String Date, String D

我正在尝试从wampserver mysql数据库将数据插入我的jtable。我不断收到这个特定错误
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:Erreur de syntaxe près de')la ligne 1.

这是我的密码

public Boolean add( String Registration,String Departure, String capacity, String Date, String Destination, String Startpoint) {
    //SQL STATEMENT
    String sql = "INSERT INTO travel_schedule( Registrationno,Capacity, Date, Destination,Departuretime,Startpoint) VALUES('"+Registration+"', '"+ capacity + "','" + Date + "','" + Destination + "','" + Departure + "','" + Startpoint + "',)";
    try {
        //GET CONNECTION
        Connection con = DriverManager.getConnection(conString, username, password);

        //PREPARED STATEMENT
        Statement s = con.prepareStatement(sql);
        s.execute(sql);
        return true;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return false;
}

在sql查询中,在此处删除逗号后的空格
Registration+“,”++
,并将其写为
Registration+“,”++
删除此处的逗号
Startpoint+“,)”

使用下面的语句

 String sql = "INSERT INTO travel_schedule(Registrationno,Capacity,Date,Destination,Departuretime,Startpoint) VALUES('"+Registration+"','"+capacity+"','"+Date+"','"+ Destination +"','"+Departure+"','" +Startpoint+"')";

修复额外的
,您必须同时删除
逗号和

 String sql = "INSERT INTO travel_schedule( Registrationno,Capacity, Date, Destination,Departuretime,Startpoint) VALUES("+ Registration +"','"+ capacity + "','" + Date + "','" + Destination + "','" + Departure
+ "','" + Startpoint + ")";

在关闭
值(…)
之前,您确实有一个
,这可能是导致异常的原因。谢谢Kevin Esche,我已删除逗号。。。我没看到。但是,exeption仍然存在,只是找不到它。您应该使用PreparedStatement,而不是所有这些字符串连接。再次感谢。汉克斯。现在很好,谢谢。现在一切正常