Answer the question
In order to leave comments, you need to log in
How to dynamically define conditions for a parametrized select?
Hello.
For example, I have a parametrized select
String sql = "SELECT STUDENT FROM SCHOOL WHERE SCHOOL LIKE ? ";
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, "Waterloo%");
ResultSet rs = prepStmt.executeQuery();
SELECT STUDENT FROM SCHOOL WHERE
SCHOOL LIKE "Waterloo%" or SCHOOL LIKE "Stackloo%"
String sql = "SELECT STUDENT FROM SCHOOL WHERE SCHOOL LIKE ? OR SCHOOL LIKE ?";
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, filter_select);
prepStmt.setString(2, filter_select);
ResultSet rs = prepStmt.executeQuery();
Answer the question
In order to leave comments, you need to log in
There is no special built-in mechanism in jdbc. You must first generate a string for a new request with parameters, then set these parameters. Or prepare several queries with different conditions and also parameterize them before execution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question