刷新(插入新的)JTable行

时间:2012-10-01 15:17:45

标签: java swing arraylist jtable odbc

我与SQL服务器有一个JTable,当我尝试更新一行时,除了第一行之外,所有单元格都会更新,因为这行不在我的构造函数中。所以我尝试手动更改它             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();
    }   

0 个答案:

没有答案