javafx - How to fill up a TableView with SQL data -


i've been trying load tableview data queried database, can't seem work.

this first attempt @ trying fill database database query items, in case code seems mungled , far good.

the fxml done via javafx scenebuilder.

this database query class:

public static void refreshtableapplicant(){       dataapplicant = fxcollections.observablearraylist();       try {             connection con = login.getconnection();             statement stmt = con.createstatement();             if (login.getentitlement() < 3) {                 resultset rs = stmt.executequery("select * applicant");                 while (rs.next()) {                     observablelist<string> applicant = fxcollections.observablearraylist();                     applicant.add(rs.getstring(1));                     applicant.add(rs.getstring(5));                     applicant.add(rs.getstring(6));                     applicant.add(rs.getstring(8));                     applicant.add(rs.getstring(9));                     applicant.add(rs.getstring(10));                     applicant.add(rs.getstring(11));                     applicant.add(rs.getstring(13));                     applicant.add(rs.getstring(14));                     applicant.add(rs.getstring(16));                     applicant.add(rs.getstring(19));                     applicant.add(rs.getstring(7));                     applicant.add(rs.getstring(20));                     dataapplicant.add(applicant);                     system.out.println(dataapplicant);                  }             }             else {                 resultset rs = stmt.executequery(                         "select * applicant inner join relationship r on r.applicantid = a.applicantid inner join vacancy v on v.vacancyid = r.vacancyid v.divisionid = "                                 + login.getdivisionid());                 while (rs.next()) {                     observablelist<string> applicant = fxcollections.observablearraylist();                     applicant.add(rs.getstring(1));                     applicant.add(rs.getstring(5));                     applicant.add(rs.getstring(6));                     applicant.add(rs.getstring(8));                     applicant.add(rs.getstring(9));                     applicant.add(rs.getstring(10));                     applicant.add(rs.getstring(11));                     applicant.add(rs.getstring(13));                     applicant.add(rs.getstring(14));                     applicant.add(rs.getstring(16));                     applicant.add(rs.getstring(19));                     applicant.add(rs.getstring(7));                     applicant.add(rs.getstring(20));                                                dataapplicant.add(applicant);                 }             }              tableviewapplicant.getitems().addall(dataapplicant);         } catch (sqlexception e) {             system.out.println("mainwindowcontroller - refreshtableapplicant");             e.printstacktrace();         }          }    

this error get:

[[100002, doe, john, mainstreet, 2, 14572, chicago, 045404245, 156451231, doe.john@googlemail.com, manager, 1994-11-24, mit]] java.lang.nullpointerexception @ trilabfx.gui.mainwindowcontroller.refreshtableapplicant(mainwindowcontroller.java:114) @ trilabfx.login.login.login(login.java:30) @ trilabfx.login.logincontroller.btnloginpressed(logincontroller.java:77) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ sun.reflect.misc.trampoline.invoke(unknown source) @ sun.reflect.generatedmethodaccessor1.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ sun.reflect.misc.methodutil.invoke(unknown source) @ javafx.fxml.fxmlloader$methodhandler.invoke(unknown source) @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle(unknown source) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source) @ com.sun.javafx.event.eventutil.fireeventimpl(unknown source) @ com.sun.javafx.event.eventutil.fireevent(unknown source) @ javafx.event.event.fireevent(unknown source) @ javafx.scene.node.fireevent(unknown source) @ javafx.scene.control.button.fire(unknown source) @ com.sun.javafx.scene.control.behavior.buttonbehavior.mousereleased(unknown source) @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(unknown source) @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(unknown source) @ com.sun.javafx.event.compositeeventhandler$normaleventhandlerrecord.handlebubblingevent(unknown source) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(unknown source) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(unknown source) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(unknown source) @ com.sun.javafx.event.eventutil.fireeventimpl(unknown source) @ com.sun.javafx.event.eventutil.fireevent(unknown source) @ javafx.event.event.fireevent(unknown source) @ javafx.scene.scene$mousehandler.process(unknown source) @ javafx.scene.scene$mousehandler.access$1500(unknown source) @ javafx.scene.scene.impl_processmouseevent(unknown source) @ javafx.scene.scene$scenepeerlistener.mouseevent(unknown source) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(unknown source) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.lambda$handlemouseevent$350(unknown source) @ com.sun.javafx.tk.quantum.glassvieweventhandler$$lambda$197/522491302.get(unknown source) @ com.sun.javafx.tk.quantum.quantumtoolkit.runwithoutrenderlock(unknown source) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(unknown source) @ com.sun.glass.ui.view.handlemouseevent(unknown source) @ com.sun.glass.ui.view.notifymouse(unknown source) @ com.sun.glass.ui.win.winapplication._runloop(native method) @ com.sun.glass.ui.win.winapplication.lambda$null$145(unknown source) @ com.sun.glass.ui.win.winapplication$$lambda$36/2117255219.run(unknown source) @ java.lang.thread.run(unknown source) 

this part of fxml file:

<tab fx:id="tabapplicant" text="applicant">               <content>                 <anchorpane minheight="0.0" minwidth="0.0" prefheight="1080.0" prefwidth="1920.0">                        <children>                           <hbox layoutx="234.0" layouty="116.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0">                              <children>                                 <tableview fx:id="tableviewapplicant" layoutx="234.0" layouty="116.0" prefheight="200.0" prefwidth="200.0" hbox.hgrow="always">                                   <columns>                                     <tablecolumn prefwidth="-1.0" text="applicant-id" />                                     <tablecolumn prefwidth="-1.0" text="name" />                                     <tablecolumn prefwidth="-1.0" text="firstname" />                                     <tablecolumn prefwidth="-1.0" text="street" />                                     <tablecolumn prefwidth="-1.0" text="housenr" />                                     <tablecolumn prefwidth="-1.0" text="postalcode" />                                     <tablecolumn prefwidth="-1.0" text="city" />                                     <tablecolumn prefwidth="-1.0" text="telefon home" />                                     <tablecolumn prefwidth="-1.0" text="telefon mobil" />                                     <tablecolumn prefwidth="-1.0" text="e-mail" />                                     <tablecolumn prefwidth="-1.0" text="vacancy" />                                     <tablecolumn prefwidth="-1.0" text="birthday" />                                     <tablecolumn prefwidth="-1.0" text="educationalachievement" />                                   </columns>                                    <columnresizepolicy>                                       <tableview fx:constant="constrained_resize_policy" />                                    </columnresizepolicy>                                 </tableview>                              </children>                           </hbox>                        </children></anchorpane>               </content>             </tab> 

the method accessed login class:

    public static int login(string username, string password) {     try {         con = drivermanager.getconnection("jdbc:sqlserver://localhost:1433;databasename=trilab;user=trilab;password=trilab");         statement stmt = con.createstatement();         resultset rs = stmt.executequery("select entitlement, employeeid, divisionid employee loginname = '"+ username + "' , password = '" + password + "'");         while (rs.next()) {             entitlement = rs.getint(1);             id = rs.getint(2);             divisionid = rs.getint(3);             mainwindowcontroller.refreshtableapplicant();             return entitlement;         }     } catch (exception e) {         system.out.println("login - login");         e.printstacktrace();     }     return 0; } 


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -