通过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 = ?"
);
版权声明:本文为qq_40675635原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。