將string數(shù)組轉(zhuǎn)化為sql的in條件用sql查詢
更新時(shí)間:2014年05月21日 16:06:41 作者:
將string數(shù)組轉(zhuǎn)化為sql的in條件就可以用sql查詢了,下面是具體是的示例,大家可以參考下
例如:我想將String[] str = {"4","5","6"}轉(zhuǎn)化為“‘4',‘5',‘6'”字符串。這樣我就可以用sql查詢:select * from tableName id in (字符串)了。
項(xiàng)目中實(shí)現(xiàn)的源碼如下:
StringBuffer idsStr = new StringBuffer();
for (int i = 0; i < ids.length; i++) {
if (i > 0) {
idsStr.append(",");
}
idsStr.append("'").append(ids[i]).append("'");
}
我自己想到的另一種方式實(shí)現(xiàn)如下:
public static String stringArray2Strin(String[] str) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length; i++) {
sb.append("'").append(str[i]).append("'").append(",");
}
return sb.toString().substring(0, sb.length() - 1);
}
public static void main(String[] args) {
String[] str = { "4", "5", "6" };
System.out.println(ItemGroupService.stringArray2String(str));
}
項(xiàng)目中實(shí)現(xiàn)的源碼如下:
復(fù)制代碼 代碼如下:
StringBuffer idsStr = new StringBuffer();
for (int i = 0; i < ids.length; i++) {
if (i > 0) {
idsStr.append(",");
}
idsStr.append("'").append(ids[i]).append("'");
}
我自己想到的另一種方式實(shí)現(xiàn)如下:
復(fù)制代碼 代碼如下:
public static String stringArray2Strin(String[] str) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length; i++) {
sb.append("'").append(str[i]).append("'").append(",");
}
return sb.toString().substring(0, sb.length() - 1);
}
public static void main(String[] args) {
String[] str = { "4", "5", "6" };
System.out.println(ItemGroupService.stringArray2String(str));
}
相關(guān)文章
解決Windows 10家庭版安裝SQL Server 2014出現(xiàn).net 3.5失敗問題
在安裝SQL Server 2014的過程中,出現(xiàn).net 3.5缺失,導(dǎo)致失敗問題。怎么解決此問題呢?下面小編給大家分享解決Windows 10家庭版安裝SQL Server 2014出現(xiàn).net 3.5失敗問題,一起看看吧2017-04-04
SQL判斷是否"存在",還在用 count 操作?很耗時(shí)的!
這篇文章主要介紹了SQL判斷是否"存在",還在用 count 操作?很耗時(shí)的!本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
sqlserver數(shù)據(jù)庫獲取數(shù)據(jù)庫信息
這篇文章主要介紹了sqlserver數(shù)據(jù)庫獲取數(shù)據(jù)庫文件信息,大家參考使用吧2014-01-01
SQL?Server?數(shù)據(jù)庫基礎(chǔ)編程詳解
這篇文章主要為大家介紹了SQL?Server?數(shù)據(jù)庫基礎(chǔ)編程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-01-01
在數(shù)據(jù)庫中自動(dòng)生成編號(hào)的實(shí)現(xiàn)方法分享
一直很討厭存儲(chǔ)過程,沒想到今天幫了我大忙啊,或許會(huì)因?yàn)榻裉熳屛衣矚g上存儲(chǔ)過程吧,不多說了,切入正題2011-10-10
SQL統(tǒng)計(jì)連續(xù)登陸3天用戶的實(shí)現(xiàn)示例
最近有個(gè)需求,求連續(xù)登陸的這一批用戶,本文就來介紹一下SQL統(tǒng)計(jì)連續(xù)登陸3天用戶的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05
SQL Server中數(shù)據(jù)行批量插入腳本的存儲(chǔ)實(shí)現(xiàn)
這篇文章主要介紹了SQL Server中數(shù)據(jù)行批量插入腳本的存儲(chǔ)實(shí)現(xiàn) 的相關(guān)資料,需要的朋友可以參考下2015-12-12

