我已通过使用 TableModelListener 直接在 Jtable 单元格中键入内容来为数据库设置值。但更新后我无法重新加载 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);
}
}
最佳答案
您应该调用 super.GetValueAt()。如果您想从数据库重新加载数据,您将必须重新初始化模型,这很大程度上取决于您如何实现模型。
关于java - 当我在 gui 中更新一行时,如何从数据库重新加载 Jtable 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9233963/