Customer liked with appointment table

This commit is contained in:
Nikitha
2026-02-23 16:10:51 -07:00
parent 287995b22c
commit c3ed8b0921
2 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package org.example.petshopdesktop.database;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.example.petshopdesktop.models.Customer;
import java.sql.*;
public class CustomerDB {
//
// GET ALL CUSTOMERS
//
public static ObservableList<Customer> getCustomers()
throws SQLException {
ObservableList<Customer> list =
FXCollections.observableArrayList();
Connection conn = ConnectionDB.getConnection();
String sql = "SELECT * FROM customer";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
Customer c = new Customer(
rs.getInt("customerId"),
rs.getString("firstName"),
rs.getString("lastName"),
rs.getString("email"),
rs.getString("phone")
);
list.add(c);
}
conn.close();
return list;
}
}

View File

@@ -0,0 +1,75 @@
package org.example.petshopdesktop.models;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class Customer {
private SimpleIntegerProperty customerId;
private SimpleStringProperty firstName;
private SimpleStringProperty lastName;
private SimpleStringProperty email;
private SimpleStringProperty phone;
// Constructor
public Customer(int customerId,
String firstName,
String lastName,
String email,
String phone) {
this.customerId = new SimpleIntegerProperty(customerId);
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
this.email = new SimpleStringProperty(email);
this.phone = new SimpleStringProperty(phone);
}
// Getters
public int getCustomerId() {
return customerId.get();
}
public String getFirstName() {
return firstName.get();
}
public String getLastName() {
return lastName.get();
}
public String getEmail() {
return email.get();
}
public String getPhone() {
return phone.get();
}
// Properties (optional but useful later)
public SimpleIntegerProperty customerIdProperty() {
return customerId;
}
public SimpleStringProperty firstNameProperty() {
return firstName;
}
public SimpleStringProperty lastNameProperty() {
return lastName;
}
public SimpleStringProperty emailProperty() {
return email;
}
public SimpleStringProperty phoneProperty() {
return phone;
}
// This controls how customer appears in ComboBox
@Override
public String toString() {
return getFirstName() + " " + getLastName();
}
}