1

I'm using Java 7 Servlets and Tomcat 7 as server and MySQL as database. I'm trying to do some searching of users, but theres probably some problem in my SQL, can anybody see the problem? The point of it is that lasNameFragment is fragment of last name and I search in users which have this fragment inside the last name. Listing users without LIKE works fine, so problem must be somewhere in this two lines.

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

error:

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

Where the Mot is value of lastnamefragment, which I get form search input.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1097772
  • 3,499
  • 15
  • 59
  • 95

1 Answers1

6

You have a SELECT, and WHERE statement, but I don't see a FROM statement.

jake
  • 1,027
  • 8
  • 9