SQL BUG - java.sql.SQLSyntaxErrorException -已解决
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: 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 'WHERE ADMIN_NAME = 'admin' and ADMIN_PWD = 'admin'' at line 1### The error may exist in file [E:\work\codes\shop\target\shop-1.0-SNAPSHOT\WEB-INF\classes\mapper\AdminMapper.xml]### The error may involve defaultParameterMap### The error occurred while setting parameters### SQL: select admin_id, admin_name, admin_pwd, admin_realname, admin_email from t_admin; WHERE ADMIN_NAME = ? and ADMIN_PWD = ?### Cause: java.sql.SQLSyntaxErrorException: 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 'WHERE ADMIN_NAME = 'admin' and ADMIN_PWD = 'admin'' at line 1; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 'WHERE ADMIN_NAME = 'admin' and ADMIN_PWD = 'admin'' at line 1] with root causejava.sql.SQLSyntaxErrorException: 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 'WHERE ADMIN_NAME = 'admin' and ADMIN_PWD = 'admin'' at lin
提示我sql语句语法出错了,
Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax;
并告诉我在这附近:
near 'WHERE ADMIN_NAME = 'admin' and ADMIN_PWD = 'admin'' at line 1
仔细检查后发现:在我的sql标签中,我在结束时候习惯性的加了分号 “;” ,在去点该分号后,不再报错。
<sql id="adminBase"> select admin_id, admin_name, admin_pwd, admin_realname, admin_email from t_admin; sql> <select id="login" resultMap="adminMap"> <include refid="adminBase"/> <where> ADMIN_NAME = #{adminName} and ADMIN_PWD = #{adminPwd} where> select>
在后面查询中我用到了这个片段,拼接后多出来的分号导致语法错误,无法顺利执行,非常低级的错误,记录下来供反思。
来源地址:https://blog.csdn.net/qq_43786840/article/details/126185628