mercredi 22 avril 2015

How to add information to a sqlite database and then display the information using javafx?

public static void addToQueueTable(Patient p) {

    try {

        // open connection to database
        conn = ConnectionFactory.getConnection();

        // create statement
        stmt = conn.createStatement();

        String sql = "insert into queueTime values('" + p.getNhsNumber()
                + "', CURRENT_TIMESTAMP)";

        // execute update
        stmt.executeUpdate(sql);

    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Error on Building Data");
    } finally {
        // close all open resources in the database
        DbUtil.close(stmt);
        DbUtil.close(conn);
    }

}

The above is my code to add details (NhsNumber and Current timestamp) to my database - just wondering how I then display this using javafx?

Patient class is as follows:

    public Patient(String nhsNumber, String firstName,
            String lastName, String postCode) {
        super(nhsNumber,firstName, lastName
                , postCode);

    }

With javafx I am able to display certain details (see below), but I'm not sure how I can get the timestamp back from the database as well? Any help would be greatly appreciated!

    public class QueueTabPageController implements Initializable {

    @FXML
    private TableView<Patient> tableView;

    @FXML
    private TableColumn<Patient, String> firstNameColumn;

    @FXML
    private TableColumn<Patient, String> lastNameColumn;

    @FXML
    private TableColumn<Patient, String> postCodeColumn;

    @FXML
    private QueueTabPageController queueTabPageController;

    private ObservableList<Patient> tableData;

    // public static LinkedList<Patient> displayQueue;

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {

        assert tableView != null : "fx:id=\"tableView\" was not injected: check your FXML file 'FXMLQueueTabPage.fxml'";

        firstNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("firstName"));
        lastNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("lastName"));
        postCodeColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("postCode"));

    }

    @FXML
    private void btnRefreshQueueClick(ActionEvent event) throws IOException{
        displayQueue(Queue.queue);
    }

    public void displayQueue(LinkedList<Patient> queue) {
        tableData = FXCollections.observableArrayList(queue);
        tableView.setItems(tableData);
    }

}

Aucun commentaire:

Enregistrer un commentaire