ho questa jtable:
codice:
tableData = new javax.swing.JTable();
tableData.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {},
new String [] {
"Book name", "Author", "Editor", "ISBN", "Price", "Note"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
}
);
tableData.setAutoCreateRowSorter(true);
si carica all'apertura della finestra.
ho messo poi questo evento al click su una label che richiama il codice per eseguire la query (lo stesso in apertura di finestra):
codice:
public class DoSelect {
private static Connection conn;
private static Statement stmt;
private static ResultSet rs;
public static void leggi() throws ClassNotFoundException, SQLException {
conn = DoConnection.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT name, author_name, editor_name, price, isbn, note FROM book INNER JOIN author ON book.author_id=author.author_id INNER JOIN editor ON book.editor_id=editor.editor_id");
while (rs.next()) {
String name = rs.getString("name");
String author = rs.getString("author_name");
String editor = rs.getString("editor_name");
String price = rs.getString("price");
String isbn = rs.getString("isbn");
String note = rs.getString("note");
Object[] riga = {name, author, editor, price, isbn, note};
((DefaultTableModel) FramePrincipale.getTable().getModel()).addRow(riga);
}
rs.close();
stmt.close();
}
}
il problema è che la tabella aggiunge i dati invece di aggiornarli solamente.
quindi succede che ad ogni click sulla label i dati si duplichino
come posso per effettuare solo un aggiornamento??