java - Jtable handling long running task -


i creating desktop application using java , h2 database using cardlayout , netbeans gui builder. app crud operation , used save customer data, purchases , list of products.

i load data database jtable when data grows, loading time begin slow down , application seems froze or unresponsive user. after few days of googling, have came across swingworker, thread, runnable , edt(not sure else more).

i run codes below in constructor. think problem here.

private void updatetable() {         vector<object> columnnames = new vector<object>();         vector<object> data = new vector<object>();         connection conn = new dbconnection().connect();         try {             statement st = conn.createstatement();             string numofrow = cbonumberofrow.getselecteditem().tostring();             if (numofrow == "all") {                 numofrow = "-1";             }             string query = "select c.custid \"id\",c.custname \"customer name\",c.custic \"ic\",c.custphoneno \"tel no.\",e.pointearned \"point earned\", e.totalspent \"total spent\" customer c join expenses e on c.custid = e.custid group c.custid limit " + numofrow;              resultset rs = st.executequery(query);             resultsetmetadata md = rs.getmetadata();             int columns = md.getcolumncount();              //  column names             (int = 1; <= columns; i++) {                 columnnames.addelement(md.getcolumnlabel(i)); //md.getcolumnname return original table column name instead query             }              //  row data             while (rs.next()) {                 vector<object> row = new vector<object>(columns);                  (int = 1; <= columns; i++) {                     row.addelement(rs.getobject(i));                 }                  data.addelement(row);             }              rs.close();             st.close();             conn.close();         } catch (sqlexception ex) {             joptionpane.showmessagedialog(null, ex);         }          defaulttablemodel model = new defaulttablemodel(data, columnnames) {             @override             public class getcolumnclass(int column) {                 switch (column) {                     case 1:                         return string.class;                     case 4:                         return double.class;                     case 5:                         return double.class;                     default:                         return string.class;                 }             }              @override             public boolean iscelleditable(int row, int col) {                 return false;             }         };          customertable.setmodel(model); //set custom model      } 

hope can point out mistakes , clear picture of doing correctly. in advance.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -