I am converting a query to use binding parameters:
String sql = String.format("SELECT name, age, job_code, category FROM EMPLOYEES " +
" WHERE job_code = '%s' AND job_code = '%s%s'", jobCode, jobLevel, role);
String query = "SELECT name, age, job_code, category FROM EMPLOYEES " +
" WHERE job_code = ? AND job_code = ??";
...
PreparedStatement stmt = conn.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
But when I try to use setString:
stmt.setString(1, jobCode);
stmt.setString(2, jobLevel);
stmt.setString(3, role);
The output is kinda weird:
SELECT name, age, job_code, category FROM EMPLOYEES WHERE job_code = ‘A’ AND job_code = ‘CD”EF'”
How can I make the output be correct like this?
SELECT name, age, job_code, category FROM EMPLOYEES WHERE job_code = ‘A’ AND job_code = ‘CD'”
2