Salve a tutti, come da titolo devo popolare una jTable da DB, il programma che uso è Netbeans.
Come modello di tabella devo usare un AbstractTableModel e non Default (richiesta del prof).
La classe DBTableModel che estende AbstractTableModel è stata fornita dal prof.
L'errore che mi ritorna, ripetuto varie volte è:
Resultset chiuso: getRow
non riesco proprio a capire perchè mi dia questo errore, mi setta il nome delle colonne in modo corretto, ma le righe non ci sono
Vi posto il codice:
package javaapplication9;
import java.sql.*;
import java.util.logging.Level;
import oracle.jdbc.pool.OracleDataSource;
import javax.swing.*;
import java.sql.Connection;
import javax.swing.table.DefaultTableModel;
public class MioFrame extends javax.swing.JFrame {
int pos=1;
Connection conn=null;
DBTableModel modelTable;
public MioFrame() {
initComponents();
try {
//Connessione al DB
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@//localhost:1521/xe");
ods.setUser("--------");
ods.setPassword("********");
conn=ods.getConnection();
String q="SELECT * FROM LISTADESIDERI WHERE ID_CLIENTE = ? ";
PreparedStatement stAccess =conn.prepareStatement (q, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
stAccess.setString(1,"1234567890");//con questo id sono sicura che ci sono dei dati
//eseguo la query
ResultSet rset=stAccess.executeQuery();
modelTable = new DBTableModel(rset);
jTable1.setModel(modelTable);
modelTable.setRS(rset);
rset.close();
}catch (SQLException ex) {
Logger.getLogger(MioFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(15, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(147, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MioFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}
Grazie mille a tutti