我有一个在Java中向MS SQL发送查询的需求,类似于:
select * from customer
where customer.name in ('abc', 'xyz', ...,'pqr');
但是我有一个以String类型的ArrayList形式给出的IN子句值,例如:列表看起来像{"abc","xyz",...,"pqr"}。
我创建了一个预编译语句:
PreparedStatement pStmt = conn.prepareStatement(select * from customer
where customer.name in (?));
String list= StringUtils.join(namesList, ",");
pStmt.setString(1,list);
rs = pStmt.executeQuery();
但这个列表像是"abc,xyz,..,pqr",我想要它变成"'abc','xyz',..,'pqr'",这样我可以将其传递给准备语句。
如何在Java中做到这一点而不使用GUAVA辅助库。
提前致谢!
String list= StringUtils.join(namesList, "','");
怎么样? - rzysia