【发布时间】:2018-05-30 12:39:53
【问题描述】:
我有一条我不明白的错误消息。该消息是下一个“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 中?我只有一个“标识”列我不明白为什么它不起作用?
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);
}
非常感谢
【问题讨论】:
-
您的结果集中只有一列 (A.codeA),而您正在编码 resu.getString(2)
-
我必须做一个 INNER JOIN 吗?因为我有两张桌子......