com.mysql.jdbc.exceptions.MySQLSyntaxErrorException when using PreparedStatement

后端 未结 1 702
甜味超标
甜味超标 2021-01-26 07:54

I am trying to execute a query that returns a student whose name and last name concatenated equal the search key parameter.

For that I am doing this in my class that man

1条回答
  •  无人共我
    2021-01-26 08:23

    Your problem is that you prepare the statement with

    preparedStatement = dbConnection.prepareStatement(selectSQL);
    

    which is correct, but then when you try to execute the PreparedStatement you supply the selectSQL string again:

    rs = preparedStatement.executeQuery(selectSQL);
    

    That is incorrect. You've already prepared the statement, so when the time comes to execute it you just do

    rs = preparedStatement.executeQuery();
    

    0 讨论(0)
提交回复
热议问题