I recently encountered this problem with Java PreparedStatements. I have the following code:
String selectSql1
= \"SELECT `value` FROM `sampling_numb
The solution to your problem is actually very easy, you are calling Statement.executeQuery(String) when you want to call PreparedStatement.executeQuery() -
this.stmt = con.prepareStatement(sql); // Prepares the Statement.
stmt.setInt(1, randNum); // Binds the parameter.
// return this.stmt.executeQuery(sql); // calls Statement#executeQuery
return this.stmt.executeQuery(); // calls your set-up PreparedStatement
public ResultSet select1(String sql, int randNum) {
try {
this.stmt = con.prepareStatement(sql);
stmt.setInt(1, randNum);
return this.stmt.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
for reference see below code
PreparedStatement statement = con.prepareStatement("SELECT EMP_ID,EMP_PWD FROM employee " +
"WHERE EMP_ID = '"+param1+"'");
ResultSet result = statement.executeQuery();