2012-02-10 16 views
0

我已經通過使用TableModelListener直接輸入到Jtable單元格來爲數據庫設置值。但是我無法在更新後重新加載Jtable中的數據。當我在gui中更新一行時,如何從數據庫重新加載Jtable內容?

public void setValueAt(Object value, int row, int column) { 
    String updateq = "update M_department set " + getColumnName(column) + "='" 
      + value.toString() + "' where code='" + getValueAt(row, 0) + "'"; 
    System.out.println(updateq); 
    try { 
     stmt.executeUpdate(updateq); 
    } catch (SQLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     System.out.println("Error" + e); 
    } 
} 

回答

2

你應該叫super.SetValueAt()。如果你想從數據庫中重新獲取數據,你將不得不重新初始化模型,這取決於你如何實現模型。

相關問題