jtable需要时间来显示db的数据

时间:2015-05-07 10:05:25

标签: java sql database jtable populate

我正在从SQL数据库中读取数据并将其显示在Jtable中;然后我添加其他列并进行一些计算...即使行数很少,Jtable中数据的显示时间也很长。任何提示恳求?

    public  JTable display () throws ClassNotFoundException, SQLException, ParseException{   
        java.sql.Connection sqlConnection = null;
        sqlConnection = getSQLConnection();
        Statement stmt = null;
        stmt = sqlConnection.createStatement();

        ResultSet rs = stmt.executeQuery("SELECT OFINTERNE,CMDCLIENT,CHAINE,REF,QTE,QTEBAC,DELAI,EFFECTIF,RENDEMENT,TPSn,"
                + "dateCreation,QTEPROD,datedebutpce,datedebutbac,datefinpce,termine from TEST_LAMIAA where OFINTERNE<3000 "
                + "order by chaine");

        ResultSetMetaData rsmetaData = rs.getMetaData();

        //stores the number of columns
        int colmns = rsmetaData.getColumnCount();

        // the object that will pass data to the jTable 
        DefaultTableModel dtm = new DefaultTableModel();

        Vector cl_names = new Vector();
        Vector data_rows = new Vector();

        for(int i = 1; i<(colmns+1); i++){
        cl_names.addElement(rsmetaData.getColumnName(i));

        }
        dtm.setColumnIdentifiers(cl_names);
        while(rs.next()){
            data_rows = new Vector();
        for(int j = 1; j <(colmns+1) ; j++){
            data_rows.addElement(rs.getString(j));
//            System.out.println(rs.getString(j));
        }
                dtm.addRow(data_rows);
        }
        //pass default model object into my table 

         jTable1.setModel(dtm);
        //adding columns

        TableColumn col = new TableColumn(dtm.getColumnCount() - 1);
        col.setHeaderValue("Sequence");
        jTable1.addColumn(col);
        dtm.addColumn(col);

        TableColumn date = new TableColumn(dtm.getColumnCount() - 1);
        date.setHeaderValue("Date");
        jTable1.addColumn(date);
        dtm.addColumn(date);

         TableColumn duree = new TableColumn(dtm.getColumnCount() - 1);
        duree.setHeaderValue("Duree");
        jTable1.addColumn(duree);
        dtm.addColumn(duree);

        TableColumn datFin = new TableColumn(dtm.getColumnCount() - 1);
        datFin.setHeaderValue("Date Fin");
        jTable1.addColumn(datFin);
        dtm.addColumn(datFin);

   jTable1.setModel(dtm);

       return jTable1;
   }

0 个答案:

没有答案