gpt4 book ai didi

java.sql.SQLException : Column Index out of range, 2 > 1

转载 作者:行者123 更新时间:2023-12-02 11:11:23 25 4
gpt4 key购买 nike

我有一条我不明白的错误消息。该消息是下一个“java.sql.SQLException:列索引超出范围,2 > 1”请问我的问题是不是来 self 的请求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);
}

非常感谢

最佳答案

您正在代码中使用 resu.getString(2) 访问 ResultSet 中的第二列,但您只选择了一列 A.codeA 在您的选择查询中

关于java.sql.SQLException : Column Index out of range, 2 > 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50604936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com