我在USERS 表中有两列username 和password。 如何获取username 和password 中的值并将其与程序中的另一个值进行比较。
这就是我得到的。但是,eclipse 给我一个错误:
String sql = "SELECT username, password FROM USERS WHERE username = ?";
错误:
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 '?' at line 1
最佳答案
在执行查询之前,您应该准备 sql 语句并绑定(bind)参数 ?
或使用 username
的实际值构造 sql。
前者是避免 sql 注入(inject)的方法。
关于mysql - SQL查询以在密码列中选择一个字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14595482/