【发布时间】:2015-09-08 04:36:30
【问题描述】:
当我将 SQL 结果填充到 Jtable 时,我使用数组而不是向量。但是我得到了一个著名的错误:当我想访问 JTable (tm.getValueAt(i,12)) 数据时线程“AWT-EventQueue-0”java.lang.ArrayIndexOutOfBoundsException 中出现异常,我不知道是什么导致了这个错误:
public JTable display () throws ClassNotFoundException, SQLException, ParseException{
java.sql.Connection sqlConnection = getSQLConnection();
Statement stmt = sqlConnection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT test.CHAINE,plg.Séquence,test.FAMILLE,test.REF,test.OFINTERNE,"
+ "test.CMDCLIENT,test.QTE,test.QTEBAC,test.effectif,plg.RENDEMENT,test.TPSn,"
+ "plg.THA,plg.RendPerte,plg.DateDébut,plg.Délai,plg.DateFin "
+ "from planning plg full outer join TEST_LAMIAA test on test.OFINTERNE=plg.NOF "
+ "where test.termine IS NULL "
+ "ORDER BY test.chaine,CASE WHEN plg.Séquence Is NULL Then 1 Else 0 End, plg.Séquence");
DefaultTableModel dtm = new DefaultTableModel() {
@Override
public Class<?> getColumnClass(int col) {
if (col == 1) {
return Integer.class;
} else {
//return getValueAt(0, columnIndex).getClass();
return String.class;
}
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
//ici la cellule (1, 2) est non-editable
if (columnIndex == 0 || columnIndex == 5 || columnIndex == 2 || columnIndex == 15
|| columnIndex == 3 || columnIndex ==10 || columnIndex == 4 || columnIndex == 11
|| columnIndex == 13 || columnIndex == 11)
return false;
//le reste est editable
return true;
}
};
ResultSetMetaData rsmetaData = rs.getMetaData();
//stores the number of columns
int colmns = rsmetaData.getColumnCount();
// the object that will pass data to the jTable
while (rs.next())
{
Object [] rowData = new Object[colmns];
for (int i = 0; i < colmns;i++)
{
if (rs.getObject(i+1) != null){
rowData[i] = rs.getObject(i+1);
}
}
dtm.addRow(rowData);
}
jTable1.setModel(dtm);
return jTable1;
}
public JTable modifyTable (JTable jTable) throws ClassNotFoundException, SQLException, ParseException{
Object Perte = tm.getValueAt(i,12);
}
【问题讨论】:
-
能否把错误堆栈跟踪放上以便我们更好地帮助您解决问题