Sharath N Sharath N - 1 month ago 8
Java Question

How to pass multiple search values in where condition

I connected to database in my java program. I have a situation where I need to pass filter values dynamically, filter values depends of others parts of java code

Example query: select * from table1 where id in (dynamic and multiple)?

How to pass these dynamic and multiple values using Java connection.

Answer

Try this

String query =  "select * from emp where id in(##)";

create the in clause like this

String inClause = "'abcd', 'cedf', '1234'";

String finalQuery = query.replace("##", inClause );
Comments