java - How to search SQL Database and display it on a JTable -
just title says, want search sql database , display on jtable using jtextfield on keyreleased
. i've tried:
private void jtextfield2keyreleased(java.awt.event.keyevent evt) { try{ int = (int)jtable2.getmodel().getvalueat(jtable2.getselectedrow(), 0); string query = "select fname roominfo fname '%" + jtextfield2.gettext() + "%'"; string url = "jdbc:mysql://localhost:3306/adv"; connection conn = drivermanager.getconnection(url,"root","sa"); statement st = conn.createstatement(); rs = st.executequery(query); jtable2.setmodel(dbutils.resultsettotablemodel(rs)); conn.close(); } catch (exception e) { system.err.println("got exception! "); joptionpane.showmessagedialog(null,"got exception!"); system.err.println(e.getmessage()); } // todo add handling code here: }
however, can't properly. seems problem? still doesn't search.
on keypressed
:
try{ string url = "jdbc:mysql://localhost:3306/adv"; connection conn = drivermanager.getconnection(url,"root","sa"); statement st = conn.createstatement(); string query = "select customerno, fname, roominfo fname '%" + jtextfield2.gettext() + "%'"; rs = st.executequery(query); jtable2.setmodel(dbutils.resultsettotablemodel(rs)); conn.close(); } catch (exception e) { joptionpane.showmessagedialog(null,"got exception!"); system.err.println(e.getmessage()); }
Comments
Post a Comment