代码是这个样子
public void insert(String a, String b, String c, String d, String e) {

try {
PreparedStatement pstmt = connection
.prepareStatement("Insert Into summer_basic(name,importance,thesis,from,coauthor,meeting)Value('"
+ a.replace("'", "\\'")
+ "',0"
+ ",'"
+ b.replace("'", "\\'")
+ "','"
+ c.replace("'", "\\'")
+ "','"
+ d.replace("'", "\\'")
+ "','"
+ e.replace("'", "\\'") + "')");
pstmt.execute();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
System.exit(1);
}
}
报错
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 'from,coauthor,meeting)Value('jhdsfhhkjsagjl',0,'ad','da','ad','faf')' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3124)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1149)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:790)
at Controller.DatabaseController.insert(DatabaseController.java:195)
at Relating.Access2.main(Access2.java:222)
望高人解答,谢谢。

解决方案 »

  1.   

    from是关键字这样可以吗?
    你改成这样的[from]试试
      

  2.   

    这个错误报的是语法错误,建议在程序中对要插入的字段内容进行replace处理。
      

  3.   

    sql语句错误,常用的方法是在文本编辑器进行书写,然后粘贴至数据库控制台进行调试!
      

  4.   

    你可以在MYSQL下运行一下你的命令,看看是否哪里错了!!