Skip to content

dorian-adams/CRUD-Grazioso-JavaFX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaFX CRUD App

demo

This CRUD application is designed to intake and track an animal's training status for a mock company, Grazioso.

Technologies

  • Java
  • JavaFX
  • FXML
  • JDBC
  • MySQL
  • Feather Dependency Injection

Features

  • Sortable table view
  • Input validation
  • GUI

Code Snippets

Initialize the table:

    /** Initialize TableView. */
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        try {
            colName.setCellValueFactory(data -> data.getValue().animalNameProperty());
            colSpecies.setCellValueFactory(data -> data.getValue().animalSpeciesProperty());
            colLocation.setCellValueFactory(data -> data.getValue().locationProperty());
            colName.setCellFactory(TextFieldTableCell.forTableColumn());
            colSpecies.setCellFactory(TextFieldTableCell.forTableColumn());
            colLocation.setCellFactory(TextFieldTableCell.forTableColumn());
            tableView.setItems(animalService.getAllAnimals());
        } catch(Exception e) {
            e.printStackTrace();
        }

        // Set double-click event.
        tableView.setOnMouseClicked(click -> {
            if (click.getClickCount() == 2) {
                editAnimalWindow(getSelection());
            }
        });
    }

DAO snippet:

    public int insert(RescueAnimal animal) {
        String sql = "INSERT INTO rescue_animal (" +
                "name, " +
                "species, " +
                "gender, " +
                "age, " +
                "weight, " +
                "acquisition_date, " +
                "location, " +
                "training_status, " +
                "reserved) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";

        try (Connection conn = ds.getConnection();
             PreparedStatement stmt = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS)) {
            stmt.setString(1, animal.getName());
            stmt.setString(2, animal.getAnimalType());
            stmt.setString(3, animal.getGender());
            stmt.setInt(4, animal.getAge());
            stmt.setInt(5, animal.getWeight());
            stmt.setDate(6, animal.getAcquisitionDate());
            stmt.setString(7, animal.getLocation());
            stmt.setInt(8, animal.getTrainingStatus());
            stmt.setBoolean(9, animal.getReserved());

            int rowsAffected = stmt.executeUpdate();
            if (rowsAffected > 0) {
                ResultSet generatedKeys = stmt.getGeneratedKeys();
                if (generatedKeys.next()) {
                    return generatedKeys.getInt(1);
                } else {
                    return 0;
                }
            } else {
                return 0;
            }
        } catch (SQLException e) {
            e.printStackTrace();
            return 0;
        }
    }

Relevant Docs and Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages