-2

I don't know why main class is not functioning well. I created the main page, then, the modelling(which connect the db with the main app) and then the db(which retrieves info from the database). After creating everything, I discovered that instead of the main class displaying the result it retrieves from the db, what is shows is 'Controller @ person...'(which is the name of the package and class).

After going through the codes, Am sure there are no mistakes in the codes but maybe syntax error. Who can help me find out what is missing in the codes

public class Cbt extends Application {
    private SchoolDB sdb;
        Person person = new Person();

    TextField username, firstName, lastName, initial, password;
    GridPane addGridStaffRegLO;
    AnchorPane staffRegLO;
    Scene staffReg;
    ComboBox qualification;

    public void start(Stage theMainStage) throws DBException {
        stageCbt = theMainStage;

        border = new BorderPane();

            hbox = addHBox();
            border.setTop(addHBox());
            border.setBottom(addHDBox());
            border.setLeft(addVbox());
            border.setRight(addFlowPaneLO());
            border.setCenter(addLogReg(addGridPaneLO()));

    }

    private HBox addHBox() {

            hbox = new HBox();
            hbox.getStyleClass().add("hbox");

            hbox.getChildren().add(displayWelcomeMsg);

            return hbox;
    }

            //the vbox for left border
        private VBox addVbox() {
            vbox = new VBox();
            vbox.setPadding(new Insets(15, 12, 15, 12));
            vbox.setSpacing(10);

            return vbox;
    }

    private HBox addHDBox() {

            hbdox = new HBox();
            hbdox.getStyleClass().add("hbox");

            hbdox.getChildren().add(displayWelcomeMsg);

            return hbdox;
        }

        private HBox addSHBox() {

            hbox = new HBox();
            hbox.getStyleClass().add("hbox");

        hbox.getChildren().add(displayWelcomeMsg);

            return hbox;
        }


    private GridPane addStaffGridRegLO() {
        addGridStaffRegLO = new GridPane();
        addGridStaffRegLO.getStyleClass().add("grid");
        addGridStaffRegLO.setHgap(10);
        addGridStaffRegLO.setVgap(10);
        addGridStaffRegLO.setPadding(new Insets(0, 10, 0, 10));

        Text welcome = new Text("Welcome to the school CBT for jamb");
        welcome.setFont(Font.font("Arial", FontWeight.BOLD, 20));
        addGridStaffRegLO.add(welcome, 1, 0);

        Text ss = new Text("For both staffs and students");
        ss.setFont(Font.font("Arial", FontWeight.BOLD, 20));
        addGridStaffRegLO.add(ss, 2, 0);

        firstName = new TextField();
        addGridStaffRegLO.add(firstName, 3, 1);
        firstName.textProperty().bind(person.firstNameProperty());
        firstName.setPromptText("Enter your student firstname");
        Tooltip fn = new Tooltip();
        fn.setText("student firstname here");
        firstName.setTooltip(fn);

        lastName = new TextField();
        addGridStaffRegLO.add(lastName, 3, 2);
        lastName.textProperty().bind(person.lastNameProperty());
        lastName.setPromptText("Enter student lastname");
        Tooltip ln = new Tooltip();
        ln.setText("Student lastname here");
        lastName.setTooltip(ln);

        initial = new TextField();
        initial.textProperty().bind(person.initialProperty());
        addGridStaffRegLO.add(initial, 3, 3);
        initial.setPromptText("Staff number here");
        Tooltip initTip = new Tooltip();
        initTip.setText("Student initial here");
        initial.setTooltip(initTip);

        username = new TextField();
        addGridStaffRegLO.add(username, 3, 4);
        username.textProperty().bind(login.usernameProperty());
        username.setPromptText("Enter your username");
        Tooltip userTip = new Tooltip();
        userTip.setText("your username here");
        username.setTooltip(userTip);

        password = new PasswordField();
        addGridStaffRegLO.add(password, 3, 5);
        password.textProperty().bind(login.passwordProperty());
        password.setPromptText("Your password here");
        Tooltip pass = new Tooltip();
        pass.setText("Your passowrd here");
        password.setTooltip(pass);

    ObservableList<School> options = FXCollections.observableArrayList();

    qualification = new ComboBox(options);
        qualification.setPromptText("Staff qualification here");
        addGridStaffRegLO.add(qualification, 3, 6);

        try {
            options.addAll(SchoolDB.getAllStudents());
        } catch (DBException ex) {
            Logger.getLogger(Cbt.class.getName()).log(Level.SEVERE, null, ex);
        }

    return addGridStaffRegLO;
    }

    private AnchorPane addStaffRegLO(GridPane addGridStaffRegLO) {
        staffRegLO = new AnchorPane();
        staffRegLO.getStyleClass().add("pane");
        Register = new Button("Signup");
        HBox hb = new HBox();
        hb.getStyleClass().add("hb");
        hb.getChildren().add(Register);
        staffRegLO.getChildren().addAll(addGridStaffRegLO, hb);
// Anchor buttons to bottom right, anchor grid to top
        AnchorPane.setBottomAnchor(hb, 8.0);
        AnchorPane.setRightAnchor(hb, 5.0);
        AnchorPane.setTopAnchor(addGridStaffRegLO, 10.0);
        return staffRegLO;
    }
}

This is the model class

public class Person {
private final SimpleStringProperty firstName = new SimpleStringProperty(this, "firstName");

    public StringProperty firstNameProperty() {
        return firstName;
    }

    public final String getFirstName() {
        return firstNameProperty().get();
    }

    public void setFirstName(String firstName) {
        firstNameProperty().set(firstName);
    }

    private final SimpleStringProperty lastName = new SimpleStringProperty(this, "lastName");
    public StringProperty lastNameProperty() {
        return lastName;
    }

    public final String getLastName() {
        return lastNameProperty().get();
    }

    public void setLastName(String lastName) {
        lastNameProperty().set(lastName);
    }

    private final SimpleStringProperty initial = new SimpleStringProperty(this, "initial");
    public StringProperty initialProperty() {
        return initial;
    }

    public final String getInitial() {
        return initialProperty().get();
    }

    public void setInitial(String initial) {
        initialProperty().set(initial);
    }

    private final IntegerProperty studentId = new SimpleIntegerProperty(this, "studentId");
    public IntegerProperty studentIdProperty() {
        return studentId;
    }

    public final int getStudentId() {
        return studentIdProperty().get();
    }

    public void setStudentId(int studentId) {
        studentIdProperty().set(studentId);
    }

        public Person() {

    }

    public Person(String firstName, String lastName, String initial, int studentId) {
        setFirstName(firstName);
        setLastName(lastName);;
        setInitial(initial);
        setStudentId(studentId);

    }

And this is the database class

import java.util.ArrayList;
import java.util.List;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.*;

import controller.Person;


    public class SchoolDB {
    public static List<School> getAllStudents() throws DBException {
            String sql = "SELECT last_name, first_name, middle_name, id FROM stu_reg";
            List<School> studentsDetail = new ArrayList<>();
            Connection connection = DBUtil.getConnection();
            try (PreparedStatement ps = connection.prepareStatement(sql);
                    ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    String lastName = rs.getString("last_name");
                    String firstName = rs.getString("first_name");
                    String initial = rs.getString("middle_name");
                    int studentId = rs.getInt("id");

                    //Person p = new Person(lastName, firstName, initial, studentId);
                    School sch = new School();
                    sch.setFirstName(firstName);

                    studentsDetail.add(sch);
                }
                return studentsDetail;
            } catch (SQLException e) {
                throw new DBException(e);
            }
        }

    }

1 Answers1

-1

you don not use the control class properly in the main page

manprogram
  • 39
  • 1
  • 6