zoukankan      html  css  js  c++  java
  • java jdbc 得到像C#里的datatable一样的表格

    public ArrayList<ArrayList<String>>    getDataTale2(String sql) throws SQLException {
    
        ArrayList<ArrayList<String>> dt=new ArrayList<ArrayList<String>>();
    
        sta =(SQLServerPreparedStatement)con.prepareStatement(sql);
    
        rs=(SQLServerResultSet)sta.executeQuery();
    
    
        SQLServerPreparedStatement stmt = (SQLServerPreparedStatement)con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY );
        ResultSet rset = stmt.executeQuery();
        ResultSetMetaData rsmd = rset.getMetaData() ;
        int columnCount = rsmd.getColumnCount();
    
        ArrayList<String> listNames=new ArrayList<>();
        for (int c=0;c<columnCount;c++){
    
            String cName=rsmd.getColumnName(c+1);
    
            listNames.add(cName);
    
    
        }
        dt.add(listNames);
        while(rs.next()){
    
            ArrayList<String> list=new ArrayList<>();
    
            for (int c=0;c<columnCount;c++){
    
                String cName=rsmd.getColumnName(c+1);
    
                list.add(rs.getString(cName));
    
            }
    
            dt.add(list);
        }
        rset.close();
    
        if (rs != null) {
            rs.close();
            rs = null;
        }
        if (sta != null) {
            sta.close();
            sta = null;
        }
        if (con != null) {
            con.close();
            con = null;
        }
        return dt;
    
    }
    
  • 相关阅读:
    javascript基础
    html基础
    css基础
    django-session和cookie
    rest架构
    django-models
    django-templates
    Alignment
    ural 1225.Flags
    ural 1009. K-based Numbers
  • 原文地址:https://www.cnblogs.com/HelloQLQ/p/13911989.html
Copyright © 2011-2022 走看看