questo è il modello che rappresenta la tabella Book:
poi nel metodo dove effettuo la query:codice:package com.mattepuffo.book; public class ModelBook { private String name; private String author; private String editor; private double price; private String isbn; private String note; public ModelBook(String name, String author, String editor, double price, String isbn, String note) { this.name = name; this.author = author; this.editor = editor; this.price = price; this.isbn = isbn; this.note = note; } public String getName() { return name; } public String getAuthor() { return author; } public String getEditor() { return editor; } public double getPrice() { return price; } public String getIsbn() { return isbn; } public String getNote() { return note; } }
questo mi va a riempire un jtable con DefaultTableModel.codice:public void select() throws ClassNotFoundException, SQLException, IOException { ArrayList<ModelBook> book = new ArrayList<ModelBook>(); conn = DBManager.getInstance().getConnection(); CallableStatement cstmt = conn.prepareCall("{ CALL getBook() }"); ResultSet rs = cstmt.executeQuery(); while (rs.next()) { // String name = rs.getString("name"); // String author = rs.getString("author_name"); // String editor = rs.getString("editor_name"); // double price = rs.getDouble("price"); // String isbn = rs.getString("isbn"); // String note = rs.getString("note"); // Object[] riga = {name, author, editor, price, isbn, note}; book.add(new ModelBook(rs.getString("name"), rs.getString("author_name"), rs.getString("editor_name"), rs.getDouble("price"), rs.getString("isbn"), rs.getString("note"))); ((DefaultTableModel) FormMain.getTable().getModel()).addRow(book.toArray()); } rs.close(); cstmt.close(); }
i risultati sono tutti così:
com.mattepuffo.book.ModelBook@25474e45
so che devo ridefinire il metodo toString, ma il problema è che qui ho 5 String.
come posso fare??

Rispondi quotando
