我有一个我不明白的错误消息。该消息是下一个“ java.sql.SQLException:列索引超出范围,2> 1”
我问我问题是否来自我的请求sql吗?
String req = "Select A.CodeA from album A, collabo C where A.CodeA = C.CodeA order by 1 ";
ResultSet resu = ConnexionMySQL.getInstance().selectQuery (req);
try {
while (resu.next())
{
myList.add (new Appareil(resu.getString(1),
new Album (resu.getString(2))));
}
}
还是在我的TableModel Appareil文件中?我只有一列“ Identification”,但我不明白为什么它不起作用?
private String[] columnNames = {"Identification"};
private ArrayList <Appareil> myList;
public TableModelAppareils (ArrayList myList)
{
this.myList = myList;
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
//System.out.println("row count : " + myList.size());
return myList.size();
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public Object getValueAt(int row, int col) {
Appareil myApp = myList.get(row);
switch (col)
{
case 0 : return myApp.getAppAlb().getCodeA();
}
return null;
}
@Override
public Class getColumnClass(int c) {
switch (c)
{
case 0 : return String.class;
}
return null;
}
public void setMyList (ArrayList myList)
{
this.myList = myList;
this.fireTableDataChanged();
}
public ArrayList <Appareil> getMyList ()
{
return myList;
}
public Appareil getMyList (int index)
{
return myList.get(index);
}
非常感谢
最佳答案
您正在使用代码中的ResultSet
从resu.getString(2)
访问第二列,但是您只是在选择查询中选择了A.codeA
列