简体   繁体   English

desc附近的SQL语法错误

[英]SQL syntax error near desc

The error I get is: 我得到的错误是:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL语法有错误; 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 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'Desc)值附近使用值(1,'Sem 2','1',1,'1234','2017-11-03','2' ,3,'vnfhmj.k; / kkc')'在第1行

If I remove desc... the error is gone. 如果我删除desc...错误消失了。 Is there a limit to number of items which can be entered? 可以输入的项目数有限制吗?

Code: 码:

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 is an SQL keyword used to specify direction in an ORDER BY clause. DESC是用于在ORDER BY子句中指定方向的SQL关键字。 That's probably the problem. 那可能是问题所在。 Try surrounding it in backticks like `Desc`. 尝试将其包围在诸如“ Desc”之类的反引号中。

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. 另外,请注意将来不要将关键字或SQL函数用作字段名称,否则可能导致调试错误的难度很大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM