Monday, 15 June 2015

java - how to show a query result in jtable in netbeans -



java - how to show a query result in jtable in netbeans -

i utilize netbeans 8 , jdbc/derby , want show result of statement (join of 3 tables) in jtable. how should it? there way manually (not via java code)? when want show info single table, through table content>bound. if there way in section please allow me know.

defaulttablemodel model; public myjframeform() { initcomponents(); model = new defaulttablemodel(); jtable1.setmodel(model); model.addcolumn("ostadname"); model.addcolumn("darsname"); loadgriddata(); } public void loadgriddata() { seek { class.forname("org.apache.derby.jdbc.clientdriver"); connection con = drivermanager.getconnection("jdbc:derby://localhost/newdatabase"); statement sta = con.createstatement(); java.sql.resultset rs = sta.executequery("select ostad.naam || ' ' || ostad.naamkhanevadegi ostadname," + " dars.naam darsname" + " (ostad inner bring together ostad_dars on ostad.id=ostad_dars.oid )" + " inner bring together dars on ostad_dars.did=dars.id"); while (rs.next()) { model.addrow(new object[]{rs.getstring(1), rs.getstring(2)}); } sta.close(); con.close(); } grab (exception e) { joptionpane.showmessagedialog(null, "exception: " + e.getmessage()); } }

java netbeans jdbc jtable derby

No comments:

Post a Comment