解决方案 »

  1.   

    public static List<Map<String, String>> queryResult(String psSql) {//
    List<Map<String, String>> _lstResult = new ArrayList<Map<String, String>>();
    try {
    Statement _st = (Statement) CONN.createStatement();
    ResultSet _rs = _st.executeQuery(psSql);int columnCount = _rs.getMetaData().getColumnCount() ;  //获取列的个数
    Map<String, String> map = null;
    while(_rs.next()){                                    //while循环遍历每一行数据
    map = new HashMap<String, String>();
    for(int i = 1; i <= columnCount ; i ++){
    map.put(_rs.getMetaData().getColumnName(i).trim(), _rs.getString(i).trim()); //将当前行,通过遍历列名,放到map中
    }
    _lstResult.add(map);
    }
    _rs.close();
    _st.close();
    CONN.close();} catch (SQLException e) {
    new CustomException(e.getMessage());
    }
    return _lstResult;
    }
      

  2.   

    public static List<Map<String, String>> queryResult(String psSql) {//
    List<Map<String, String>> _lstResult = new ArrayList<Map<String, String>>();
    try {
    Statement _st = (Statement) CONN.createStatement();
    ResultSet _rs = _st.executeQuery(psSql); int columnCount = _rs.getMetaData().getColumnCount(); // 获取列的个数
    Map<String, String> map = null;
    while (_rs.next()) { // while循环遍历每一行数据
    map = new HashMap<String, String>();
    for (int i = 1; i <= columnCount; i++) {
    map.put(_rs.getMetaData().getColumnName(i).trim(), _rs
    .getString(i).trim()); // 将当前行,通过遍历列名,放到map中
    }
    _lstResult.add(map);
    }
    _rs.close();
    _st.close();
    CONN.close(); } catch (SQLException e) {
    new CustomException(e.getMessage());
    }
    return _lstResult;
    }
    把楼上代码格式化下,这样是不是好看多了