desc附近的SQL语法错误 [英] SQL syntax error near desc
问题描述
我得到的错误是:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误.检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'Desc'值(1,'Sem 2','1',1,'1234','2017-11-03','2'附近使用,3,'vnfhmj.k;/kkc')'在第1行
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 'Desc) values(1,'Sem 2','1',1,'1234','2017-11-03','2',3,'vnfhmj.k;/kkc')' at line 1
如果我删除了desc...
,该错误消失了.可以输入的项目数有限制吗?
If I remove desc...
the error is gone. Is there a limit to number of items which can be entered?
代码:
String query="insert into exam(sub_id,exam_sem,co,tch_id,ex_pwd,ex_date,ex_duration,noofq,Desc) values(?,?,?,?,?,?,?,?,?)";
PreparedStatement pstmt=DatabaseConnector.getPreparedStatement(query);
//pstmt.setInt(1,ed.getEx_id());
pstmt.setInt(1,ed.getSub_id());
pstmt.setString(2,ed.getEx_sem());
pstmt.setString(3,ed.getEx_co());
pstmt.setInt(4,ed.getT_id());
pstmt.setString(5,ed.getEx_pwd());
pstmt.setString(6,ed.getEx_date());
pstmt.setString(7,ed.getEx_duration());
pstmt.setInt(8,ed.getNoofq());
pstmt.setString(9,ed.getDesc());
推荐答案
DESC是一个SQL关键字,用于在ORDER BY子句中指定方向.那可能是问题所在.尝试将其包围在诸如"Desc"之类的反引号中.
DESC is an SQL keyword used to specify direction in an ORDER BY clause. That's probably the problem. Try surrounding it in backticks like `Desc`.
此外,请尽量避免将来再使用关键字或SQL函数作为字段名称,这可能会导致调试错误的真正困难.
Also, try to be careful not to use keywords or SQL functions as field names in the future, it can lead to really difficult to debug errors.
这篇关于desc附近的SQL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!