I have a table that gets information from my local MySQL server. It reads the data very well and post it on GUI.
My question is , how can I refresh my table when I change my table command, for example:
private String sql = "select * from profildb.tbl_detailed"; //to
private String sql = "select * from profildb.tbl_detailed where Y.."; //this
This action will be handled in my Button Action Listener ;
JButton btnOK = new JButton("");
btnOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if( (tfBirinci.getText().isEmpty() || tfBirinci.getText() == null) && (tfIkinci.getText().isEmpty() || tfIkinci.getText() == null ))
{
taLog.setText("Database alani bos birakilamaz...\n");
}
else if ( (!(tfBirinci.getText().isEmpty() )) && (tfIkinci.getText().isEmpty() || tfIkinci.getText() == null ) )
{
sql = ("SELECT * FROM " + tfBirinci.getText());
taLog.setText("Komut elde edildi : " + sql + "\n");
System.out.println("aaaa " + tfBirinci.getText());
//anaFrame.dispose();
//databaseHistoryCalistir(); doesnt work
}
else if ( ( !(tfBirinci.getText().isEmpty() ) && !(tfBirinci.getText() == null) ) && ( !(tfIkinci.getText().isEmpty() ) && !(tfBirinci.getText() == null) ) )
{
sql = ("SELECT * FROM " + tfBirinci.getText() + " WHERE " + tfIkinci.getText());
taLog.setText("Komut elde edildi : " + sql + "\n" );
System.out.println("bbbb " + tfBirinci.getText());
//anaFrame.dispose();
//databaseHistoryCalistir(); doesnt work
}else
taLog.setText("Lütfen Database alanini doldurunuz, aksi taktirde komut elde edilemez...\n");
}
});
So , what I need to implement for ONLY update the table when I change the statement of my string ?
Thanks in advance. (It would be awesome to give an example about DefaultTableModel)
Edit , You can see my full code here : http://pastebin.com/eQCJVuKn
1) use Table from Database by @camickr
2) use one of
ResultsetTableModel3) call SQL statement from
Runnable#Thread, but output to theXxxTableModelmust be insideinvokeLater, more in the Concurency in Swing aboutEvent Dispatch Thread (EDT)4) call SQL statement from SwingWorker, then output from
progress(),publish()ordone()should be on EDT5)
DefaultTableModeldoesn’t required override methodsfireXxxTableXxx, all of them are correctly implemented6) difference betweens logics
Table from Database (ResultsetTableModel)andRunnable#Thread(SwingWorker)isTable from Database (ResultsetTableModel)calling all updates on EDT, then GUI waiting for all event are done, during loading data from database is GUI unresponsible or freezeRunnable#Thread(SwingWorker)all updates are from backgourng task and GUI is resposible for Mouse and Keyboard events,