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.
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 );
If you are using iBatis, you can try with below sql query:-
<select id="table1Result" resultMap="table1Map">
select * from table1 where id in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"</select>
While calling it from java, pass a List of ids.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.