如何在SQL查询中传递列表 [英] How to pass List in sql query
本文介绍了如何在SQL查询中传递列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有值(例如 1、2、3
),并且我想将该列表传递给SQL查询:
I have of values (1, 2, 3
, for example), and I want to pass that list to a SQL query:
"select name from tbl where id in" + list
我将如何实现?
推荐答案
您必须将列表直接放入sql语句
you have to put your list directly to sql statement
示例:
String sql="select name from tbl where id in ("+StringUtils.join(list, ',')+")";
Statement st=connection.createStatement();
st.execute(sql);
这篇关于如何在SQL查询中传递列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文