使用 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。
最佳答案
不需要单引号,试试这个:
ResultSet rs = stmt.executeQuery("select * from user_tbl where user_id = " + user);
如果 user_id 是非整数,则用单引号将 user
变量括起来
关于mySQL语法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20965892/