Hello guys, I am very new to Java. I've been trying to select two different tables but fails. The error is "Invalid operation at current cursor position.". Here is my code.

private void display() throws SQLException{
        TableModel model = schedTable.getModel();
        PreparedStatement stmt = con.prepareStatement("select * from APP.SCHEDULE");
        ResultSet sched = stmt.executeQuery();
            stmt = con.prepareStatement("select * from APP.SUBJECT where subjectNum='OOP2'");
            ResultSet subj = stmt.executeQuery();
            model.setValueAt(sched.getInt("numOfStud"), 0, 0);
            model.setValueAt(subj.getString("name"), 0, 1);

As you can see, I am still learning this stuff. I haven't fully understood how statement and resultset works yet. I would very much appreciate it if you would explain it to me.

solved it already. All I needed was a subj.next(). dang Im so dumb. Took me 3 hours to solve that.

You better have a look at your line 14. Here you are trying to access


where as you have not checked whether subj has a result from executing the query.
Since you are using a conditionalized SQL you can use in line 14 like

  model.setValueAt(subj.getString("name"), 0, 1);
This question has already been answered. Start a new discussion instead.