将JDBC查询的结果转成List,再拼接在一起的方法
将JDBC查询的结果转成List,再拼接在一起的方法:
conn = getConnection();pstmt = conn.prepareStatemen(sql); pstmt.setString(1, id); rs = pstmt.executeQuery(); while(rs.next()){ list.add(rs.getString(1)); } StringBuffer sb = new StringBuffer(); //用一个StringBuffer 方法来进行遍历拼接Iterator it = list.iterator();boolean isNull = it.hasNext();while (isNull) {Object o = it.next();sb.append(String.valueOf(o));if (isNull) {sb.append("; ");}} return sb;//拼接的结果