我JTable
与 SQL 服务器有关系,当我尝试更新一行时,除了第一个单元格之外的所有单元格都会更新,因为该行不在我的构造函数中。所以我尝试手动更改它,
tableAlbum.setValueAt(artistName, tableAlbum.getSelectedRow(), 0);
但表格没有更新。当我手动刷新框架时,单元格以正确的值正确显示。
这是我的代码:
else if (e.getSource() == btnConfirm) {
String artistName = (String) tableAlbum.getValueAt(tableAlbum.getSelectedRow(), 0);
tableAlbum.setValueAt(artistName, tableAlbum.getSelectedRow();
modele.editAlbum(tableAlbum.getSelectedRow(), tile, price, genre, year, home, "");
有我的 editMethod :
public void modifierAlbum(int num, String title, double price, String genre,
String year, String home, String image) {
Album album = null;
Statement statement;
try {
statement = connexion.createStatement();
String query = "USE albums UPDATE Album SET title='"+title+"', price = "+price+", genre = '"+genre+"', year = '"+year+"', home = '"+home+"' WHERE titre = '"+title+"'";
statement.executeUpdate(query);
album = new Album(title, price, genre, year, home);
getData().set(num, album);
fireTableRowsUpdated(0, data.size());
} catch (SQLException e) {
e.printStackTrace();
}