java.sql.SQLException:列索引超出范围,2> 1

时间:2018-05-30 12:39:54

标签: java sql swing

我有一条我不明白的错误消息。消息是下一个“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);
    }

非常感谢

1 个答案:

答案 0 :(得分:1)

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