使用try-catch短语我在以下代码中捕获错误:
ResultSet rs = stmt.executeQuery("select * from 'user_tbl' where user_id = '"+user+"' ");
错误详情如下:
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 ''user_tbl' where user_id = '12345678'' at line 1
我的语法有什么问题吗?我使用Netbeans作为我的IDE。
答案 0 :(得分:0)
你不应该在里面有user_tbl'标记,尝试删除它们,使其显示为:
ResultSet rs = stmt.executeQuery(
"select * from user_tbl where user_id = '"+user+"' ");
答案 1 :(得分:0)
不需要单引号,请尝试:
ResultSet rs = stmt.executeQuery("select * from user_tbl where user_id = " + user);
如果user_id是非整数,则将user
变量括在单引号中