0

I want to display content of an Oracle Database in my TableView "FilmTable". The structure of the Oracle Databade is: a table column named "FILMTITEL" in the table "LUKA1". The are 4 Film names like Fast and Furious, ...

Hope you can help me and i hope i understand your Solutions to solve my Problem.

I made this code and i got this Errors:

    javafx.fxml.LoadException: 
/D:/Users/muellerl/workspace/Table_DB/bin/application/gui.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:15)
    at com.sun.javafx.application.LauncherImpl$8.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$7.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$6.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at controller.table_controller.initialize(table_controller.java:39)
    ... 20 more

If I remove all Table-Code-Contents the error isn't there.

Here is my code i hope you can help me to Display this things.

Main.java

    package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource(
                    "/application/gui.fxml"));
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

table_controller.java:

package controller;

import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

import oracle.jdbc.*;
import model.filmtable_data;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class table_controller implements Initializable {
    Connection conn;
    String output;
    int zaehler = 0;

    @FXML
    private TableView<filmtable_data> FilmTable;
    @FXML
    private TableColumn<filmtable_data, String> Filmtitel_col;
    @FXML
    private TableColumn<filmtable_data, Integer> ID_col;



    @Override
    public void initialize(URL location, ResourceBundle resources) {
        // Observable List
        final ObservableList<filmtable_data> data = FXCollections.observableArrayList();
        ID_col.setCellValueFactory(new PropertyValueFactory<filmtable_data, Integer>("rID"));
        Filmtitel_col.setCellValueFactory(new PropertyValueFactory<filmtable_data, String>("rFilmtitel"));
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            Connection conn = DriverManager.getConnection("jdbc:oracle:thin:lukas/1234@10.140.79.39:1521:OTTO");
            Statement statement = conn.createStatement();
            ResultSet resultset = statement.executeQuery("SELECT FILMTITEL FROM LUKA1");

            while (resultset.next()) {
                output = resultset.getString(1);
                zaehler++;
                filmtable_data entry = new filmtable_data(zaehler, output);
                data.add(entry);
                System.out.println (resultset.getString(1));
                System.out.println(output);
                }
            FilmTable.setItems(data);
            statement.close();
        }   catch (SQLException e) {
                System.out.println("Login fehlgeschlagen.");
                e.printStackTrace();
        }
    }   
}

filmtable_data.java:

package model;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;

public class filmtable_data {

    private final SimpleIntegerProperty rID;
    private final SimpleStringProperty rFilmtitel;

    public filmtable_data (Integer sID, String sFilmtitel) {
        this.rID = new SimpleIntegerProperty(sID);
        this.rFilmtitel = new SimpleStringProperty(sFilmtitel);
    }

    public Integer getRID() {
        return rID.get();
    }

    public void setRID(int set) {
        rID.set(set);
    }

    public String getRFilmtitel() {
        return rFilmtitel.get();
    }

    public void setRFilmtitel(String set) {
        rFilmtitel.set(set);
    }
}
  • Which is line 39? Have you checked that your `fx:id` attributes are set correctly? – James_D Oct 21 '14 at 15:14
  • Here is a [sample for loading data from a database using jdbc](http://stackoverflow.com/questions/14878788/javafx-background-thread-for-sql-query) into JavaFX which uses an embedded H2 database, but using oracle should be similar as it uses the same same standard jdbc API. – jewelsea Oct 21 '14 at 20:47
  • Ok the ID fxid was wrong. But it doesn't Displays me the id in the table anyway. the film titles are there –  Oct 22 '14 at 06:34
  • It's done. I have it. Forgot to Change the getters and setter because of the fxid Name. –  Oct 22 '14 at 06:56

0 Answers0