com.mysql.jdbc.exception,您的SQL语法有错误;

亚辛·哈立德(Yassine Khalid)

我不知道为什么会有这个错误...如果有人可以告诉我这是怎么回事:

com.mysql.jdbc.exception,您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以使用正确的语法

mat_pay="maybe";
Class.forName("com.mysql.jdbc.Driver");
connec = DriverManager.getConnection("jdbc:mysql://localhost/babe","root","");
stmt = connec.prepareStatement("INSERT INTO ? VALUES ( , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ");
                stmt.setString(1,mat_pay);
                stmt.setInt(2,septembre.var_m_p_g1); //septembre.var_m_p_g1 has a value 'integer'
                stmt.setInt(3,id_g2); //septembre.var_m_p_g1 has a value 'integer'
                stmt.setInt(4,0);
                stmt.setInt(5,0);
                stmt.setInt(6,0);
                stmt.setInt(7,0);
                stmt.setInt(8,0);
                stmt.setInt(9,0);
                stmt.setInt(10,0);
                stmt.setInt(11,0);
                stmt.setInt(12,0);
                stmt.setInt(13,0);
                stmt.executeUpdate();
吉姆·加里森

您不能将表名替换为?占位符。该语句必须显式命名表。如果确实需要这样做(SQL注入易受攻击),则可以使用字符串格式动态构建语句

// assuming mat_pay is the name of a variable containing the table name
String query = String.format("INSERT INTO %s VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", mat_pay);

stmt = connec.prepareStatement(query);
stmt.setInt(1,septembre.var_m_p_g1); //septembre.var_m_p_g1 has a value 'integer'
stmt.setInt(2,id_g2); //septembre.var_m_p_g1 has a value 'integer'
stmt.setInt(3,0);
stmt.setInt(4,0);
stmt.setInt(5,0);
stmt.setInt(6,0);
stmt.setInt(7,0);
stmt.setInt(8,0);
stmt.setInt(9,0);
stmt.setInt(10,0);
stmt.setInt(11,0);
stmt.setInt(12,0);
stmt.executeUpdate();

中的值mat_pay不应是用户/客户端输入的值,而应完全由您控制,并且不受外部操纵。否则,您很容易受到SQL Injection攻击的影响。

请注意,值列表的开头还带有一个逗号。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的 SQL 语法有错误;(休眠)

SQL语法错误:“ com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;”

春季休眠错误OneToMany关系:错误:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误

线程“ main”中的异常com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误

EclipseLink: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你的 SQL 语法有错误

MYSQL:您的 SQL 语法有错误

MYSQL错误:com.mysql.jdbc.NotUpdatable

MySQL错误1064:您的SQL语法有错误

mysql console> mysqlbinlog您的SQL语法有错误

Hibernate和MYSQL:您的SQL语法有错误吗?

Hibernate和MYSQL:您的SQL语法有错误吗?

您的SQL语法中有错误-休眠和mysql

显示#1064的mysql查询-您的SQL语法有错误;

mysql error您的SQL语法有错误

1064“您的SQL语法有错误; ...” Python MySQL

MySQL说:文档(#1064)-您的SQL语法有错误;

错误com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

MySQL 语法错误 SQL 错误 [1064] [42000]:您的 SQL 语法有错误

在JDBC中转义单引号(出现错误:您的SQL语法有错误...)

“您的SQL语法有错误;请查看与您的MySQL相对应的手册”

错误MySql您的SQL语法有错误。当添加带有变量的参数时

MySQL错误-插入时出现“您的SQL语法有错误”

MySQL数据库错误返回#1064-您的SQL语法有错误;

Hibernate,MySQL,Spring MVC,Freemarker:java.sql.SQLSyntaxErrorException:您的SQL语法有错误

错误:java.lang.ClassNotFoundException:com.mysql.jdbc.Driver

C#/MySQL - 如何修复此异常消息:“您的 SQL 语法有错误”?

_mysql_exceptions.ProgrammingError:(1064,“您的SQL语法有错误;

rails 4:Mysql2 :: Error:您的SQL语法有错误

MySQL语法错误?JDBC