I am creating a search form for my application.In it, the user selects the fields that should be used to filter data.numeric fields are variables, so I don’t know how much ?should be in the place of the SQL query sentence.How can I use preparedStatementwith a variable number of conditions in where where?
?
preparedStatement
thank
PrepardStatements does not support variable number conditions. What some frameworks do, they cache every PreparedStatement on a map where the key is a request.
, , , PreparedStatement, , ( ), , .
, StringBuilder (StringBuffer, env.) conciate/append .
like
StringBuilder query = new StringBuilder("Select id, name from Student "); if(args >0) { query.append(" where "); //and add more args.
,
PrepareStatement(query.toString());