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

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


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 {

    private TableView<Patient> tableView;

    private TableColumn<Patient, String> firstNameColumn;

    private TableColumn<Patient, String> lastNameColumn;

    private TableColumn<Patient, String> postCodeColumn;

    private QueueTabPageController queueTabPageController;

    private ObservableList<Patient> tableData;

    // public static LinkedList<Patient> displayQueue;

    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"));


    private void btnRefreshQueueClick(ActionEvent event) throws IOException{

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


Aucun commentaire:

Enregistrer un commentaire