简体   繁体   中英

SQL syntax error near desc

The error I get is:

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

If I remove desc... the error is gone. 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. That's probably the problem. Try surrounding it in backticks like `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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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