java - How to get selected rows from a database into a jTable? -
i have database table has many patient details registration id, registration date etc. want perform date based search of patients , result jtable. ( example, if type 23-05-2013 registration date, patients admitted on 23 may should displayed in jtable. how do that?
this code have used:
public void gettabledata() { try { con = getconnection.getcon(); string sql = "select * patientrecords registration date = ?"; pst.setstring(1, regdate.gettext()); pst = con.preparestatement(sql); rs = pst.executequery(); if (rs.next()) { patient_table.setmodel(dbutils.resultsettotablemodel(rs)); } } catch (sqlexception e) { joptionpane.showmessagedialog(null, e); } }
1) should make own tablemodel
implementation or extending abstracttablemodel
2) map patientrecords
object world. entity name should in singular. have java-bean patientrecord
.
3) you'll have list<patientrecord> data
dataholder.
fill
while (rs.next()) { data.add(new patientrecord(..)); }
4) in part should set in jtable.setmodel(..)
this previous question may simple code populate jtable resultset
Comments
Post a Comment