Passing parameters to a JDBC PreparedStatement

后端 未结 6 721
星月不相逢
星月不相逢 2020-11-28 11:45

I\'m trying to make my validation class for my program. I already establish the connection to the MySQL database and I already inserted rows into the table. The table consis

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 12:26

    If you are using prepared statement, you should use it like this:

    "SELECT * from employee WHERE userID = ?"
    

    Then use:

    statement.setString(1, userID);
    

    ? will be replaced in your query with the user ID passed into setString method.

    Take a look here how to use PreparedStatement.

提交回复
热议问题