今天在写sql语句查询数据库时,范了一个容易被忽略的错误:

这是报错信息:
java.sql.SQLException: 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,typeId from goods where id = ‘7’’ at line 1 Query: select id,img,name,desc,typeId from goods where id = ? Parameters: [7]
原因:name 和 desc 是sql固有的关键字,使用的时候需要加反引号
解决办法:

成功解决!
SQL关键字冲突解决
本文分享了一次在SQL查询中遇到的错误经历,由于使用了SQL保留关键字作为字段名,导致语法错误。通过在关键字周围加上反引号,成功解决了问题。
16万+

被折叠的 条评论
为什么被折叠?



