list<123l,456l, 789l>
List
List.add("1231");
List.add("4561");
List.add("7891");
list参数这样装的吗
import java.util.ArrayList;
import java.util.List;
public class T2 {
/**
* @param args
*/
public static void main(String[] args) {
Listlist = new ArrayList ();
list.add("1231");
list.add("4561");
list.add("7891");
sqlIn(list);
}
public static void sqlIn(Listlist){
StringBuilder sb = new StringBuilder();
if(list != null && list.size()>0){
for(int i=0,len=list.size();isb.append("'"+ list.get(i) + "'");
if(i < len-1){
sb.append(",");
}
}
}
System.out.println(sb.toString());
//'1231','4561','7891'
}
}
package com;
import java.util.Arrays;
import java.util.List;
public class Kyo
{
public static void main(String[] args)
{
Listlist = Arrays.asList("1231","4561","7891");
String sql = "select * from table where id in ";
sql += list.toString().replaceAll("\\[", "(").replaceAll("\\]", ")");
System.out.println(sql);
}
}
方法很多,可以写一个util