我有一个从本地 MySQL 服务器获取信息的表。它可以很好地读取数据并将其发布在 GUI 上。
我的问题是,当我更改表命令时如何刷新表,例如:
private String sql = "select * from profildb.tbl_detailed"; //to
private String sql = "select * from profildb.tbl_detailed where Y.."; //this
此操作将在我的 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");
}
});
那么,当我更改字符串的语句时,我只需要更新表就需要实现什么?
提前致谢。(举一个关于 DefaultTableModel 的例子会很棒)
编辑,你可以在这里看到我的完整代码:http: //pastebin.com/eQCJVuKn