2013-01-25 20 views
1

我使用Java 7 Servlets和Tomcat 7作爲服務器和MySQL作爲數據庫。 我試圖做一些用戶搜索,但在我的SQL可能有一些問題,有人可以看到這個問題?關鍵在於lasNameFragment是姓氏的片段,我在名字中包含這個片段的用戶中搜索。列出沒有使用LIKE的用戶可以正常工作,所以問題必須出現在這兩行中。
在java中使用類似於MySQL的MySQL選擇Servlet MySQL錯誤

preparedStatement = connection.prepareStatement("SELECT users.id AS id, login, name, lastname, password, sex, birth, info WHERE lastname LIKE ?;"); 
    preparedStatement.setString(1, "%" + lastNameFragment + "%"); 

錯誤:

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 

凡蒙特是lastnamefragment的價值,這是我得到的形式搜索輸入。

+1

...信息'FROM yourTableName'其中... – xQbert

回答

6

你有一個SELECT和WHERE語句,但我沒有看到一個FROM語句。

+0

謝謝,我忽略了我錯過了FROM。 – user1097772