I want to connect my PostgreSQL database to JavaFX in a way that when the user enters the command in the text field, the label or the table view displays the query result. Here is my code for that which I receive a null connection error.
P.S. The picture of the UI which I have added may explain the situation better
public class ListController {
@FXML
public TextField sqlTextField;
@FXML
public Label textLabel;
public void handleSaveButton(ActionEvent actionEvent) {
}
public void handleRunButton(ActionEvent actionEvent1) throws SQLException {
ConnectionClass connectionClass = new ConnectionClass();
Connection connection = connectionClass.getConnection();
String sql = sqlTextField.getText() + ";";
Statement statement = connection.createStatement();
statement.executeUpdate(sql);
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
textLabel.setText(resultSet.getString(1));
}
}
}