java.sql.SQLException: индекс столбца вне диапазона, 2> 1 - PullRequest
0 голосов
/ 30 мая 2018

У меня есть сообщение об ошибке, которое я не понимаю.Это следующее сообщение «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 голосов
/ 30 мая 2018

Вы получаете доступ ко второму столбцу из ResultSet, используя resu.getString(2) в своем коде, однако вы просто выбираете один столбец A.codeA в своем запросе выбора

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...