java - Display data on a Jtable after excuting a search -
basically code searching first name or surname in table. once search has been done, example 'peter' , occur data placed text boxes.
the issue want data displayed onto table, have tried many times not seem work, have tried using line of code. 'table_stats' name of table. table_stats.setmodel(dbutils.resultsettotablemodel(result));
i pretty new this, can 1 please help, appreciated thank you!
private void searchkeyreleased(java.awt.event.keyevent evt) { // todo add handling code here: try{ string sql = "select * statistics first_name =? " ; string sql2 = "select * statistics surname =? " ; prepared=conn.preparestatement(sql); prepared=conn.preparestatement(sql2); prepared.setstring (1, search.gettext()); result = prepared.executequery(); if(result.next()){ string add1 = result.getstring("player_id"); player_id.settext(add1); string add2 = result.getstring("first_name"); first_name.settext(add2); string add3 = result.getstring("surname"); surname.settext(add3); string add4 = result.getstring("goal_scored"); goal_scored.settext(add4); string add5 = result.getstring("assist"); assist.settext(add5); } } catch(exception e) { joptionpane.showmessagedialog(null, e); } }
i think can use defaultablemodel: (http://docs.oracle.com/javase/7/docs/api/javax/swing/table/defaulttablemodel.html)
or can implement own subclass of abstractablemodel: (http://docs.oracle.com/javase/7/docs/api/javax/swing/table/abstracttablemodel.html)
anyway should separate code querying database table gui code (for example create separate class method getplayers returns table model).