Question: I am currently trying to load data into my tableview from the localhost, but I get this black screen once I click on the top

I am currently trying to load data into my tableview from the localhost, but I get this black screen once I click on the top "Query_1" button. I do not receive an error particularly, but I believe the issue lies in the controller with the commented out bold elements. So the information is coming just presented as a black screen.

Main:

package sample; import animatefx.animation.FadeIn; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); primaryStage.setScene(new Scene(root, 1200, 575)); new FadeIn(root).play(); primaryStage.show(); } Button loadBtn= new Button(); public static void main(String[] args) { launch(args); } }

UserDetails:

package sample; import javafx.beans.property.*; public class UserDetails { private final IntegerProperty memberId; private final StringProperty fullName; private final StringProperty emailAddress; private final StringProperty dateOfBirth; private final StringProperty mailingAddress; private final BooleanProperty registered; public UserDetails(Integer memberId, String fullName, String emailAddress, String dateOfBirth, String mailingAddress, Boolean registered) { this.memberId = new SimpleIntegerProperty(memberId); this.fullName = new SimpleStringProperty(fullName); this.emailAddress = new SimpleStringProperty(emailAddress); this.dateOfBirth = new SimpleStringProperty(dateOfBirth); this.mailingAddress = new SimpleStringProperty(mailingAddress); this.registered = new SimpleBooleanProperty(registered); } //getters public Integer getMemberId(){ return memberId.get();} public String getFullName(){ return fullName.get();} public String getEmailAddress() { return emailAddress.get();} public String getDateOfBirth() { return dateOfBirth.get(); } public String getMailingAddress() { return mailingAddress.get(); } public Boolean getRegistered() { return registered.get(); } //Setters public void setMemberId(Integer value) { memberId.set(value); } public void setFullName(String value) { fullName.set(value); } public void setEmailAddress(String value) { emailAddress.set(value); } public void setDateOfBirth(String value) { dateOfBirth.set(value); } public void setMailingAddress(String value) { mailingAddress.set(value); } public void setRegistered(Boolean value) { registered.set(value); } // public IntegerProperty memberIdProperty() { // return memberId; // } // public StringProperty fullNameProperty() { // return fullName; // } }
                                                    

Controller:

package sample; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import java.lang.reflect.Member; import java.net.URL; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ResourceBundle; public class Controller implements Initializable { @FXML public TableView Tb1; @FXML public TableColumncolumnMemberId; @FXML public TableColumncolumnFullName; @FXML public TableColumncolumnEmailAddress; @FXML public TableColumncolumnDateOfBirth; @FXML public TableColumncolumnMailingAddress; @FXML public TableColumncolumnRegistered; @FXML public Button loadBtn; @FXML public ObservableList data; @FXML public dbConnection dc; @Override public void initialize(URL url, ResourceBundle rb) { dc = new dbConnection(); } @FXML private void loadD(ActionEvent e) { Connection conn = null; try { conn = dbConnection.connect(); } catch (SQLException e1) { e1.printStackTrace(); } data = FXCollections.observableArrayList(); try { ResultSet rs = null; if (conn != null) { rs = conn.createStatement().executeQuery("SELECT * FROM member"); } if (rs != null) { while (rs.next()){ data.add(new UserDetails(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getBoolean(6))); } } } catch (SQLException e1) { e1.printStackTrace(); } columnMemberId.setCellValueFactory(new PropertyValueFactory("MemberId")); columnFullName.setCellValueFactory(new PropertyValueFactory("FullName")); columnEmailAddress.setCellValueFactory(new PropertyValueFactory("EmailAddress")); columnDateOfBirth.setCellValueFactory(new PropertyValueFactory("dateOfBirth")); columnMailingAddress.setCellValueFactory(new PropertyValueFactory("mailingAddress")); columnRegistered.setCellValueFactory(new PropertyValueFactory("registered")); Tb1.setItems(null); Tb1.setItems(data); } }

Connection:

package sample; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class dbConnection { private static Connection conn; private static String url = "jdbc:mysql://localhost:3306/"; private static String user = "";//Username of database; Omitted user info private static String pass = "";//Password of database; Omitted password info public static Connection connect() throws SQLException{ try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); }catch(ClassNotFoundException cnfe){ System.err.println("Error: "+cnfe.getMessage()); }catch(InstantiationException ie){ System.err.println("Error: "+ie.getMessage()); }catch(IllegalAccessException iae){ System.err.println("Error: "+iae.getMessage()); } conn = DriverManager.getConnection(url,user,pass); return conn; } public static Connection getConnection() throws SQLException, ClassNotFoundException{ if(conn !=null && !conn.isClosed()) return conn; connect(); return conn; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!