gpt4 book ai didi

java - 如何在 Java 中将整数的 HashSet 转换为逗号分隔的字符串

转载 作者:行者123 更新时间:2023-12-01 21:35:19 26 4
gpt4 key购买 nike

我想将整数的 HashSet 转换为逗号分隔的字符串,

所以我可以在 MySQL 查询的 where 子句中使用相同的内容。

//[MySQL - Sample table Schema]
my_table
state_id INTEGER
shop_id INTEGER
Set<Integer> uniqueShopIds = shopService.GetShopIds(); // This returns HashSet<Integer>
String inClause = ; // **How do i convert the uniqueShopIds to comma separated String**
String selectQuery = String.format("SELECT DISTINCT(state_id) FROM my_table WHERE shop_id IN (%s);", inClause);

如果有其他方法,我可以直接在PreparedStatment的IN CLAUSE中使用HashSet,请分享。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com