How to use a variable in preparedstatement for sql query?

前端 未结 2 1826
抹茶落季
抹茶落季 2021-01-29 09:58

I am doing a web-application project in eclipse Java EE. Currently, my application returns all values in the database which stores personal information of employees. However, I

2条回答
  •  庸人自扰
    2021-01-29 10:25

    You need to use parameters in your prepared statement, e.g. as follows:

    PreparedStatement ps = con.prepareStatement("select ... where employeeID = ?");
    ps.setInt(1, 1234);
    

    Or with a named parameter:

    PreparedStatement ps = con.prepareStatement("select ... where employeeID = :employeeId");
    ps.setInt("employeeId", 1234);
    

提交回复
热议问题