Passing parameters to a JDBC PreparedStatement

后端 未结 6 723
星月不相逢
星月不相逢 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:20

    You can use '?' to set custom parameters in string using PreparedStatments.

    statement =con.prepareStatement("SELECT * from employee WHERE  userID = ?");
    statement.setString(1, userID);
    ResultSet rs = statement.executeQuery();
    

    If you directly pass userID in query as you are doing then it may get attacked by SQL INJECTION Attack.

提交回复
热议问题