Question: I have a SQL database attached to my Java project, I ' m not getting an errors and the table is updating in the console

I have a SQL database attached to my Java project, I'm not getting an errors and the table is updating in the console and database but not in GUI
titleCol.setCellValueFactory(cellData -> cellData.getValue().titleProperty());
TableColumn authorCol = new TableColumn>( s: "Author");
authorCol.setCellValueFactory(cellData -> cellData.getValue().authorProperty());
TableColumn statusCol = new TableColumn>( s: "Status");
statusCol.setCellValueFactory(cellData -> cellData.getValue().statusProperty());
// Add columns to table
table.setItems(data);
table.getColumns().addAll(idCol, titleCol, authorCol, statusCol);
// Create a layout and add table
VBox vbox = new VBox();
vbox.getChildren().addAll(table);
// Create scene and add it to stage
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.setTitle("Book Library");
stage.show();
}
private void loadBooksFromDatabase(){ nousages
BookLibraryCon bookLibraryCon = new BookLibraryCon();
bookLibraryCon.getBooks().forEach(book -> data.add(book));
}
```
package com.example.s200project;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BookLibraryCon {
public List getBooks(){1 usage
List books = new ArrayList>();
String query = "SELECT * FROM books";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement stmt = conn.prepareStatement(query);
ResultSet rs = stmt.executeQuery()){
while (rs.next()){
Book book = new Book(
rs.getString( columnLabel: "id"),
rs.getString( columnLabel: "title"),
rs.getString( columnLabel: "author"),
BookStatus.valueOf(rs.getString( columnLabel: "status"))
);
books.add(book);
}
} catch (SQLException e){
e.printStackTrace();
}
return books;
}
}
``` Book.java
BookApp.java
BookLibraryCon.java
shelf
DatabaseConnection.java
BookTracker.java
3 rows
Tx: Auto
DDL
CSV
\(7\cdot \) WHERE
\(\cdot \) ORDER BY
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline & & \(\square \) Book_title \(
abla \) & & D] Author \(
abla \) & & (D) Status \(
abla \) & \(*\)\\
\hline 1 & 1 & Harry Potter and the Order of the Phoniex & & Jk Rowling & & Completed & \\
\hline 2 & 2 & Pucked & & Helena Hunting & & Completed & \\
\hline 3 & 3 & A Long Time Coming & & Meghan Quinn & & Completed & \\
\hline
\end{tabular}
Book Library
ID
Title
Author
Status
No content in table ```
public class BookApp extends Application {
private final TableView table = new TableView>(); 3 usages
private final ObservableList data = FXCollections.observableArrayList(); 2 usages
public static void main(String[] args){ launch(args); }
@Override
public void start(Stage stage){
// Define Table Columns
TableColumn idCol = new TableColumn>( s: "ID");
idCol.setCellValueFactory(cellData -> cellData.getValue().idProperty());
TableColumn titleCol = new TableColumn>( s: "Title");
titleCol.setCellValueFactory(cellData -> cellData.getValue().titleProperty());
TableColumn authorCol = new TableColumn>( s: "Author");
authorCol.setCellValueFactory(cellData -> cellData.getValue().authorProperty());
TableColumn statusCol = new TableColumn>( s: "Status");
statusCol.setCellValueFactory(cellData -> cellData.getValue().statusProperty());
// Add columns to table
table.setItems(data);
table.getColumns().addAll(idCol, titleCol, authorCol, statusCol);
// Create a layout and add table
VBox vbox = new VBox();
vbox.getChildren().addAll(table);
// Create scene and add it to stage
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.setTitle("Book Library");
stage.show();|
}
private void loadBooksFromDatabase(){ nousages
BookLibraryCon bookLibraryCon = new BookLibraryCon();
bookLibraryCon.getBooks().forEach(book -> data.add(book));
}
```
I have a SQL database attached to my Java

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 Programming Questions!