ecco il mio model , ma è unico per tutte le tabelle che utilizzo .
codice:
public class ModelloTabella extends AbstractTableModel {
public ModelloTabella(ResultSet aResultset){
rs = aResultset;
try{
rsmd = rs.getMetaData();
}catch (SQLException e){e.printStackTrace();}
}
public String getColumnName(int c){
try{
//metodo che setta i nomi delle colonne
String str=rsmd.getColumnName(c+1);
if(str.equals("mlst"))str="MLST";
if(str.equals("mlimp"))str="MLIMP";
if(str.equals("mlord"))str="MLORD";
if(str.equals("mqst"))str="MQST";
if(str.equals("mqimp"))str="MQIMP";
if(str.equals("mqord"))str="MQORD";
return str;
}catch(SQLException e){e.printStackTrace(); return "";}
}
public int getColumnCount() {
// metodo che conta le colonne
try{
return rsmd.getColumnCount();
}catch(SQLException e){e.printStackTrace(); return 0;}
}
public int getRowCount() {
//metodo che conta le righe
try{
rs.last();
return rs.getRow();
}catch(SQLException e){e.printStackTrace();return 0;}
}
public Object getValueAt(int r, int c) {
// metodo che aggiunge l'oggetto alla tabella
try{
rs.absolute(r+1);
return rs.getObject(c+1);
}catch(SQLException e){e.printStackTrace();return null;}
}
private ResultSet rs;
private ResultSetMetaData rsmd;
}