解决报错You have an error in your SQL syntax; check the manual….
•
数据库
通过JDBC查询数据库时出现了以下报错
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 'user_role.user_id = 1' at line 1

检查语法是没有问题的,但是忽略了一点。
var selectionStatement = connection.prepareStatement(
"SELECT role.role_name AS roleName from user_role" +
" INNER JOIN role on user_role.role_id= role.id"+
"WHERE user_role.user_id = ?"
);
原来是代码中SQL语句拼接时,WHERE关键字前面没有加空格导致与前面的字符串混在一起。修改后解决报错问题。
var selectionStatement = connection.prepareStatement(
"SELECT role.role_name AS roleName from user_role" +
" INNER JOIN role on user_role.role_id= role.id"+
" WHERE user_role.user_id = ?"
);
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/b88561f827.html
