use*_*772 1 mysql jdbc prepared-statement sql-like
我使用Java 7 Servlets和Tomcat 7作为服务器,使用MySQL作为数据库.我正在尝试对用户进行一些搜索,但是我的SQL中可能存在一些问题,有人能看到问题吗?关键是lasNameFragment是姓氏的片段,我搜索在姓氏中有这个片段的用户.没有LIKE的列表用户工作正常,所以问题必须在这两行中的某个地方.
preparedStatement = connection.prepareStatement("SELECT users.id AS id, login, name, lastname, password, sex, birth, info WHERE lastname LIKE ?;");
preparedStatement.setString(1, "%" + lastNameFragment + "%");
Run Code Online (Sandbox Code Playgroud)
错误:
com.mysql.jdbc.exceptions.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 'WHERE lastname LIKE '%Mot%'' at line 1
Run Code Online (Sandbox Code Playgroud)
Mot是lastnamefragment的值,我得到表单搜索输入.
| 归档时间: |
|
| 查看次数: |
806 次 |
| 最近记录: |