mysql - Unable to populate table with data from database -


i have problem when trying fetch data database , display in database. user input , store search variable. how set table:

//i user input perform search @fxml  public void searchresident(actionevent event){      string search=gettb_search().gettext();       if(search.equals("")){          dialogs.showerrordialog(null, "please enter something", "blank fields detected", "");     }else{           setupsearchtable(search);        }  }   //how set table  public void setupsearchtable(string search) {     tablecolumn rmnamecol = new tablecolumn("name");     rmnamecol.setvisible(true);     rmnamecol.setcellvaluefactory(new callback<tablecolumn.celldatafeatures<searchneedyresidentcontroller, string>, observablevalue<string>>() {         public observablevalue<string> call(tablecolumn.celldatafeatures<searchneedyresidentcontroller, string> p) {             return p.getvalue().searchnameproperty();         }     });      tablecolumn rmnriccol = new tablecolumn("nric");     rmnriccol.setcellvaluefactory(new propertyvaluefactory<searchneedyresidentcontroller, string>("search_nric"));     rmnriccol.setminwidth(150);      tablecolumn rmphnocol = new tablecolumn("phone number");     rmphnocol.setcellvaluefactory(new propertyvaluefactory<searchneedyresidentcontroller,string>("search_phno"));     rmphnocol.setminwidth(350);      tablecolumn rmincomecol = new tablecolumn("income($)");     rmincomecol.setcellvaluefactory(new propertyvaluefactory<searchneedyresidentcontroller, string>("search_income"));     rmincomecol.setminwidth(100);      residentmanagement.entity.needyresidententity searchvalue= new residentmanagement.entity.needyresidententity();     //viewproduct.setcolumnresizepolicy(tableview.constrained_resize_policy);     table_search.seteditable(false);     table_search.getcolumns().addall(rmnriccol, rmnamecol, rmincomecol, rmphnocol);     table_search.getitems().setall(searchvalue.searchresident(search));  } }   //how populate table data  public list<searchneedyresidentcontroller> searchresident(string search){ list ll = new linkedlist();     try {         dbcontroller db = new dbcontroller();         db.getconnection();         string sql = "select * rm_needyresident name '" + search + "%'";         resultset rs = null;         // call readrequest result         rs = db.readrequest(sql);          while (rs.next()) {             string nric=rs.getstring("nric");             string name = rs.getstring("name");             double income = rs.getdouble("familyincome");             string incomestr = new decimalformat("##.00").format(income);             string phno = rs.getstring("phno");              searchneedyresidentcontroller row = new searchneedyresidentcontroller();             row.setsearchnric(nric);             row.setsearchname(name);             row.setsearchincome(incomestr);             row.setsearchphno(phno);             ll.add(row);         }         rs.close();     } catch (sqlexception ex) {         ex.printstacktrace();         system.out.println("error sql!!!");         system.exit(0);     } catch (exception e) {         e.printstacktrace();     }     return ll; } } 

when search button on click, table column displayed. however, it's show blank table though there's matching result. debug , think error @ retrieving data in searchresident method. it's not retriving data database. know what's wrong?

thanks in advance.

try dis one...

   @fxml private void searchbutton()       {               connection c ;         datamem = fxcollections.observablearraylist();        try         {           c = dao.getcon();           string sql =select * `member`;            resultset rs = c.createstatement().executequery(sql);           if(table.getcolumns().isempty())           {             for(int i=0 ; i<rs.getmetadata().getcolumncount(); i++)             {                 final int j = i;                                tablecolumn col = new tablecolumn(rs.getmetadata().getcolumnname(i+1));                 col.setcellvaluefactory(new             callback<tablecolumn.celldatafeatures<observablelist,string>,observablevalue<string>>(){                                    public observablevalue<string>    call(tablecolumn.celldatafeatures<observablelist, string> param) {                                                                                                              return new simplestringproperty(param.getvalue().get(j).tostring());                                            }                                    });                  table.getcolumns().addall(col);             }//for           }//if          while(rs.next())           {               observablelist<string> row = fxcollections.observablearraylist();               for(int i=1 ; i<=rs.getmetadata().getcolumncount(); i++)                 {                     row.add(rs.getstring(i));                 }//                datamem.add(row);           }//while           table.setitems(datamem);         }//try         catch(exception e)         {             joptionpane.showmessagedialog(null, "problem in search button "+e);         }     }//else }//else 

} //search method


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -