1

Hello I am new to Java and I am getting an error while running the application. The application runs but when a button click event createStudent(ActionEvent event) is invoked the errors show. I am pasting the full error stack trace.

javafx.fxml.LoadException: 
/home/user/IdeaProjects/JavaFxDemo/out/production/JavaFxDemo/resources/fxml/newStudent.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2571)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at dashboard.Controller.createStudent(Controller.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2566)
    ... 65 more
Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:666)
    at com.mysql.jdbc.ResultSet.next(ResultSet.java:7274)
    at dashboard.AdmissionController.initialize(AdmissionController.java:168)
    ... 75 more

I checked whether there is any problem with the fxml file in the below location, but there is no problem there.

javafx.fxml.LoadException: 
/home/user/IdeaProjects/JavaFxDemo/out/production/JavaFxDemo/resources/fxml/newStudent.fxml

Please check my Controller files

dashboard.Controller.java

package dashboard;

import java.io.IOException;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.IdentityHashMap;
import java.util.Observable;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import dashboard.StudentMaster;
import database.DatabaseAccess;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.sql.Connection;

public class Controller {


    private Connection connection;

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private TableView<StudentMaster> studentTable;

    @FXML
    private TableColumn<StudentMaster, Integer> studID;

    @FXML
    private TableColumn<StudentMaster, String> studReg;

    @FXML
    private TableColumn<StudentMaster, String> stdAdm;

    @FXML
    private TableColumn<StudentMaster, String> stdName;

    @FXML
    private TableColumn<StudentMaster, String> stdClass;

    @FXML
    private TableColumn<StudentMaster, String> stdDiv;

    @FXML
    private TextField regBox;

    @FXML
    private TextField admBox;

    @FXML
    private TextField nameBox;

    @FXML
    private TextField classBox;

    @FXML
    private TextField divBox;

    @FXML
    private Button searchBtn;

    @FXML
    private Button createStudentBtn;

    private ObservableList<StudentMaster> data;



    public void buildData(String SQL)
    {
        data = FXCollections.observableArrayList();
        try {
            ResultSet rs = connection.createStatement().executeQuery(SQL);
            while(rs.next())
            {
                StudentMaster studentData = new StudentMaster();
                studentData.studentId.set(rs.getInt("student_id"));
                studentData.stdClass.set(rs.getString("student_std"));
                studentData.name.set(rs.getString("student_name"));
                studentData.admNo.set(rs.getString("student_admn_no"));
                studentData.regno.set(rs.getString("student_regno"));
                studentData.stdDiv.set(rs.getString("student_div"));
                data.add(studentData);
                studentTable.setItems(data);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @FXML
    void initialize() {
        assert studentTable != null : "fx:id=\"studentTable\" was not injected: check your FXML file 'dashboard.fxml'.";
        assert studID != null : "fx:id=\"studID\" was not injected: check your FXML file 'dashboard.fxml'.";
        assert studReg != null : "fx:id=\"studReg\" was not injected: check your FXML file 'dashboard.fxml'.";
        assert stdAdm != null : "fx:id=\"stdAdm\" was not injected: check your FXML file 'dashboard.fxml'.";
        assert stdName != null : "fx:id=\"stdName\" was not injected: check your FXML file 'dashboard.fxml'.";
        assert stdClass != null : "fx:id=\"stdClass\" was not injected: check your FXML file 'dashboard.fxml'.";
        assert stdDiv != null : "fx:id=\"stdDiv\" was not injected: check your FXML file 'dashboard.fxml'.";

        DatabaseAccess newConnection = new DatabaseAccess();
        connection = newConnection.startConnection();
        String SQL = "Select * from student";
        buildData(SQL);
        newConnection.shutdown();

        loadDataToTable();

    }

    private void loadDataToTable()
    {
        studID.setCellValueFactory(new PropertyValueFactory<StudentMaster, Integer>("studentId"));
        studReg.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("regno"));
        stdName.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("name"));
        stdAdm.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("admNo"));
        stdClass.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("stdClass"));
        stdDiv.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("stdDiv"));
    }

    @FXML
    void createStudent(ActionEvent event)
    {
        FXMLLoader fxmlLoader;
        fxmlLoader = new FXMLLoader(getClass().getResource("/resources/fxml/newStudent.fxml"));
        try {
            Parent root1 = (Parent)fxmlLoader.load();
            AdmissionController admissionController = fxmlLoader.getController();
            admissionController.setStudentData(studentTable.getItems());
            Stage stage = new Stage();
            stage.initModality(Modality.APPLICATION_MODAL);
//            stage.initStyle(StageStyle.UNDECORATED);
            stage.setTitle("New Admission");
            stage.setScene(new Scene(root1));
            stage.show();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    @FXML
    void searchBtnClicked(ActionEvent event)
    {
        String name = nameBox.getText();
        String regno = regBox.getText();
        String admno = admBox.getText();
        String stdClass = classBox.getText();

        String SQL = "Select * from student where student_name like '"+name+"%'";
        System.out.println(SQL);
        DatabaseAccess newConnection = new DatabaseAccess();
        connection = newConnection.startConnection();
        buildData(SQL);
        newConnection.shutdown();
        loadDataToTable();
    }

    public void reloadStudentTable()
    {
        loadDataToTable();
    }

}

dashboard.AdmissionController.java

package dashboard;

import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.InputMethodEvent;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import customlib.ExecuteSQL;
import dashboard.AvailableClasses;

import java.sql.ResultSet;
import java.sql.SQLException;

public class AdmissionController {


    @FXML
    private TextField nameBox;

    @FXML
    private ChoiceBox<String> classBox;

    @FXML
    private ChoiceBox<String> divBox;

    @FXML
    private TextField admBox;

    @FXML
    private TextField religionBox;

    @FXML
    private TextField casteBox;

    @FXML
    private TextArea addressBox;

    @FXML
    private DatePicker dobBox;

    @FXML
    private ChoiceBox<?> sexBox;

    @FXML
    private Button resetBtn;

    @FXML
    private Button cancelBtn;

    @FXML
    private Button doneBtn;

    @FXML
    void cancelBtnClicked(ActionEvent event)
    {
//        GET the current node of the event
        Node node = (Node)event.getSource();
        Stage stage = (Stage)node.getScene().getWindow();
        stage.close();
    }

    @FXML
    void classMouseClicked(MouseEvent event) throws SQLException {
        System.out.println("clicked");
    }

    private ObservableList<StudentMaster> data ;
    private ObservableList<AvailableClasses>totalClasses;

    public void setStudentData(ObservableList<StudentMaster> data)
    {
        this.data = data ;
    }

    @FXML
    void doneBtnClicked(ActionEvent event)
    {
        String name = nameBox.getText();
        Integer ref = 1;
        String standard = "1";
        String division  = "A";
        String admissionNo = admBox.getText();
        String sex = "M";
        String religion = religionBox.getText();
        String caste = casteBox.getText();
        String address = addressBox.getText();
        String SQLquery = "INSERT INTO student (student_name," +
                "fk_grp_ref,"+
                "student_std," +
                "student_div," +
                "student_admn_no," +
                "student_sex," +
                "student_religion," +
                "student_caste," +
                "student_address) " +
                "VALUES ('"+name+"','"+ref+"', '"+standard+"'," +
                " '"+division+"', '"+admissionNo+"', '"+sex+"', " +
                "'"+religion+"', '"+caste+"', '"+address+"')";

        ExecuteSQL newQuery = new ExecuteSQL();
        Integer executeStatus = newQuery.ExecuteSQL(SQLquery);
        if (executeStatus != 0)
        {
            System.out.println("Data Inserted");
        }
        else
        {
            System.out.println("Error in execution");
        }
        StudentMaster student = new StudentMaster();
        StudentMaster studentData = new StudentMaster();
        studentData.name.set(name);
        studentData.admNo.set(admissionNo);
        studentData.stdDiv.set(division);
        studentData.stdClass.set(standard);
        studentData.studentId.set(executeStatus);
        data.add(studentData);




//      Close the Window after successfully inserted

        Node node = (Node)event.getSource();
        Stage stage = (Stage)node.getScene().getWindow();
        stage.close();

    }

    @FXML
    void resetBtnClicked(ActionEvent event) {
        nameBox.setText("");
        addressBox.setText("");
        admBox.setText("");
        dobBox.getEditor().clear();
        religionBox.setText("");
        casteBox.setText("");
    }

    @FXML
    void initialize() throws SQLException {
        assert nameBox != null : "fx:id=\"nameBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert classBox != null : "fx:id=\"classBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert divBox != null : "fx:id=\"divBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert admBox != null : "fx:id=\"admBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert religionBox != null : "fx:id=\"religionBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert casteBox != null : "fx:id=\"casteBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert addressBox != null : "fx:id=\"addressBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert dobBox != null : "fx:id=\"dobBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert sexBox != null : "fx:id=\"sexBox\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert resetBtn != null : "fx:id=\"resetBtn\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert cancelBtn != null : "fx:id=\"cancelBtn\" was not injected: check your FXML file 'newStudent.fxml'.";
        assert doneBtn != null : "fx:id=\"doneBtn\" was not injected: check your FXML file 'newStudent.fxml'.";

        String query = "select * from class";
        ExecuteSQL newSelectClassesQuery = new ExecuteSQL();
        ResultSet rs = newSelectClassesQuery.GetClassesList(query);
        totalClasses = FXCollections.observableArrayList();
        while(rs.next())
        {
//            AvailableClasses classesData = new AvailableClasses();
            classBox.getItems().add(rs.getString("class_name"));
        }
        rs.close();
    }
}

ExecuteSQL.java // To execute my SQL Queries

package customlib;


import database.DatabaseAccess;

import java.sql.*;

public class ExecuteSQL {
    private Connection connection;

    public Integer ExecuteSQL(String query)
    {
        DatabaseAccess newConnection = new DatabaseAccess();
        connection = newConnection.startConnection();
        try
        {
            PreparedStatement preparedStatement = (PreparedStatement) connection.prepareStatement(query);
            preparedStatement.executeUpdate();

            ResultSet rs = connection.createStatement().executeQuery("select last_insert_id() as last_id from student");
            int lastid = 0;
            while(rs.next())
            {
                lastid = rs.getInt("last_id");

            }

            newConnection.shutdown();
            return lastid;

        }
        catch (SQLException e)
        {
            e.printStackTrace();
            newConnection.shutdown();
            return 0;
        }


    }

    public ResultSet GetClassesList(String query)
    {
        DatabaseAccess newConnection = new DatabaseAccess();
        connection = newConnection.startConnection();
        ResultSet rs;
        try
        {
            rs = connection.createStatement().executeQuery(query);
            newConnection.shutdown();
            rs.close();
            return rs;

        }
        catch (SQLException e)
        {
            e.printStackTrace();
            newConnection.shutdown();
            rs = null;
            return rs;
        }

    }




}

EDIT: Adding newStudent.fxml file

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dashboard.AdmissionController">
   <children>
      <Pane layoutX="67.0" layoutY="92.0">
         <children>
            <TextField fx:id="nameBox" layoutX="64.0" layoutY="1.0" />
            <ChoiceBox fx:id="classBox" layoutX="299.0" onMouseClicked="#classMouseClicked" prefHeight="26.0" prefWidth="61.0" />
            <ChoiceBox fx:id="divBox" layoutX="396.0" layoutY="1.0" prefHeight="26.0" prefWidth="61.0" />
            <Label layoutY="6.0" prefHeight="16.0" prefWidth="49.0" text="Name" />
            <Label layoutX="257.0" layoutY="6.0" prefHeight="16.0" prefWidth="38.0" text="Class" />
            <Label layoutX="368.0" layoutY="5.0" prefHeight="16.0" prefWidth="38.0" text="Div" />
            <TextField fx:id="admBox" layoutX="64.0" layoutY="52.0" />
            <Label layoutX="2.0" layoutY="57.0" prefHeight="16.0" prefWidth="61.0" text="Adm.No" />
            <TextField fx:id="religionBox" layoutX="64.0" layoutY="98.0" />
            <Label layoutX="2.0" layoutY="103.0" prefHeight="16.0" prefWidth="61.0" text="Religion" />
            <TextField fx:id="casteBox" layoutX="63.0" layoutY="145.0" />
            <Label layoutX="1.0" layoutY="150.0" prefHeight="16.0" prefWidth="61.0" text="Caste" />
            <Label layoutX="251.0" layoutY="58.0" prefHeight="16.0" prefWidth="61.0" text="Address" />
            <TextArea fx:id="addressBox" layoutX="306.0" layoutY="50.0" prefHeight="116.0" prefWidth="267.0" />
            <Label layoutX="1.0" layoutY="196.0" prefHeight="16.0" prefWidth="61.0" text="DOB" />
            <DatePicker fx:id="dobBox" layoutX="61.0" layoutY="192.0" prefHeight="26.0" prefWidth="170.0" />
            <ChoiceBox fx:id="sexBox" layoutX="500.0" layoutY="1.0" prefHeight="26.0" prefWidth="61.0" />
            <Label layoutX="472.0" layoutY="5.0" prefHeight="16.0" prefWidth="38.0" text="Sex" />
            <Button fx:id="resetBtn" layoutX="2.0" layoutY="272.0" mnemonicParsing="false" onAction="#resetBtnClicked" text="Reset" />
            <Button fx:id="cancelBtn" layoutX="425.0" layoutY="271.0" mnemonicParsing="false" onAction="#cancelBtnClicked" text="Cancel" />
            <Button fx:id="doneBtn" layoutX="512.0" layoutY="269.0" mnemonicParsing="false" onAction="#doneBtnClicked" prefHeight="26.0" prefWidth="62.0" text="Done" />
         </children>
      </Pane>
      <Label layoutX="261.0" layoutY="40.0" prefHeight="25.0" prefWidth="170.0" text="NEW ADMISSION">
         <font>
            <Font size="20.0" />
         </font>
      </Label>
   </children>
</Pane>
3
  • Please add the fxml file Commented May 6, 2016 at 17:32
  • @SebastianS added that fxml file. Commented May 6, 2016 at 17:35
  • 1
    Thanks, just wanted to make sure I understand the control flow correctly. So The exception occurs in AdmissionController#initialize. Commented May 6, 2016 at 17:40

1 Answer 1

4

The problem is, that getClassesList returns a ResultSet, that is already closed:

 try {
     rs = connection.createStatement().executeQuery(query);
     newConnection.shutdown(); // why shut down the connection when you plan to work on rs?
     rs.close(); // same question applies here
     return rs;
 }

But in your AdmissionController you want to work with the ResultSet:

ResultSet rs = newSelectClassesQuery.GetClassesList(query); // already closed!
totalClasses = FXCollections.observableArrayList();
while(rs.next()) // exception
{
    // AvailableClasses classesData = new AvailableClasses();
    classBox.getItems().add(rs.getString("class_name"));
}
rs.close();

Hint: Refactor your classes ;-)

If you ask me, you should consider creating DAOs, that get and return your classes from the database. Then your UI code doesn't need to know about the ResultSet lifecycle.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for spending time to debug this. I have one doubt, when to close the database connection and the result set rs that we have opened using the statement connection = newConnection.startConnection();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.