Question: I am using Java Language with scene builder and SQLite as a database. I have created the delete button on the scene builder and have

I am using Java Language with scene builder and SQLite as a database. I have created the delete button on the scene builder and have it inside the code on the bottom line. I am having trouble setting up a delete function for the program created. I have a clear field entry where it clears the text I have input, but I need a delete entry where it will delete an entry. I am not understanding what code I need to put the delete function. I have the private void delete method setup,

package Admin; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.DatePicker; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import dbUtil.dbConnection; import javafx.scene.control.cell.PropertyValueFactory; import javafx.event.ActionEvent; import java.net.URL; import java.sql.*; import java.util.ResourceBundle; public class AdminController implements Initializable { @FXML private TextField DVD; @FXML private TextField firstname; @FXML private TextField lastname; @FXML private TextField email; @FXML private DatePicker dob; @FXML private TableView studenttable; @FXML private TableColumn DVDcolumn; @FXML private TableColumn firstnamecolumn; @FXML private TableColumn lastnamecolumn; @FXML private TableColumn emailcolumn; @FXML private TableColumn dobcolumn; @FXML private dbConnection dc; private ObservableList data; private String sql = "SELECT * FROM Customer"; public void initialize(URL url, ResourceBundle resourceBundle) { this.dc = new dbConnection(); } @FXML private void loadData(ActionEvent event) throws SQLException { try { Connection conn = dbConnection.getConnection(); this.data = FXCollections.observableArrayList(); ResultSet rs = conn.createStatement().executeQuery(sql); while (rs.next()) { this.data.add(new Data(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5))); } } catch (SQLException e) { System.err.println("Error" + e); } this.DVDcolumn.setCellValueFactory(new PropertyValueFactory("DVD")); this.firstnamecolumn.setCellValueFactory(new PropertyValueFactory("firstName")); this.lastnamecolumn.setCellValueFactory(new PropertyValueFactory("lastName")); this.emailcolumn.setCellValueFactory(new PropertyValueFactory("email")); this.dobcolumn.setCellValueFactory(new PropertyValueFactory("DOB")); this.studenttable.setItems(null); this.studenttable.setItems(this.data); } @FXML private void Add(ActionEvent event) { String sqlInsert = "INSERT INTO Customer (DVD,fname,lname,email,DOB) values (?,?,?,?,?)"; try { Connection conn = dbConnection.getConnection(); PreparedStatement stmt = conn.prepareStatement(sqlInsert); stmt.setString(1, this.DVD.getText()); stmt.setString(2, this.firstname.getText()); stmt.setString(3, this.lastname.getText()); stmt.setString(4, this.email.getText()); stmt.setString(5, this.dob.getEditor().getText()); stmt.execute(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } @FXML private void clearFields(ActionEvent event) { this.DVD.setText(""); this.firstname.setText(""); this.lastname.setText(""); this.email.setText(""); this.dob.setValue(null); } @FXML private void delete(ActionEvent event) { } } 

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!