0

I'm doing a JavaFX application part of which requires that I populate a table in a .fxml file with a ResultSet rs queried from my database.

Table: h_customers

mysql> desc h_customers;
+-------------------------------+-------------+------+-----+---------+----------------+
| Field                         | Type        | Null | Key | Default | Extra          |
+-------------------------------+-------------+------+-----+---------+----------------+
| intCustomerID                 | int(11)     | NO   | PRI | NULL    | auto_increment |
| vachCustomerTitle             | varchar(25) | NO   |     | NULL    |                |
| vachCustomerFirstName         | varchar(45) | NO   |     | NULL    |                |
| vachCustomerSurnames          | varchar(45) | NO   |     | NULL    |                |
| dteCustomerDOB                | date        | NO   |     | NULL    |                |
| vachCustomerAddressStreet     | varchar(50) | NO   |     | NULL    |                |
| vachCustomerAddressTown       | varchar(50) | NO   |     | NULL    |                |
| vachCustomerAddressCounty     | varchar(50) | NO   |     | NULL    |                |
| vachCustomerAddressPostalCode | varchar(50) | NO   |     | NULL    |                |
| intCustomerHomePhone          | int(15)     | NO   |     | NULL    |                |
| intCustomerWorkPhone          | int(15)     | NO   |     | NULL    |                |
| intCustomerMobilePhone        | int(15)     | NO   |     | NULL    |                |
| vachCustomerEmail             | varchar(45) | NO   |     | NULL    |                |
+-------------------------------+-------------+------+-----+---------+----------------+
13 rows in set (0.06 sec)

Code Snippet from my MainController.java class:

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    intCustomerID.setCellValueFactory(new PropertyValueFactory<Customer, String>("intCustomerID"));
    vachCustomerTitle.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerTitle"));
    vachCustomerFirstName.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerFirstName"));
    vachCustomerSurnames.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerSurnames"));
    dteCustomerDOB.setCellValueFactory(new PropertyValueFactory<Customer, String>("dteCustomerDOB"));
    vachCustomerAddressStreet.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerAddressStreet"));
    vachCustomerAddressTown.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerAddressTown"));
    vachCustomerAddressCounty.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerAddressCounty"));
    vachCustomerAddressPostalCode.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerAddressPostalCode"));
    intCustomerHomePhone.setCellValueFactory(new PropertyValueFactory<Customer, String>("intCustomerHomePhone"));
    intCustomerWorkPhone.setCellValueFactory(new PropertyValueFactory<Customer, String>("intCustomerWorkPhone"));
    intCustomerMobilePhone.setCellValueFactory(new PropertyValueFactory<Customer, String>("intCustomerMobilePhone"));
    vachCustomerEmail.setCellValueFactory(new PropertyValueFactory<Customer, String>("vachCustomerEmail"));

    tblCustomer.getItems().setAll(parseCustomerList());
}

private Customer parseCustomerList() {
    SelectQueries customerRS = new SelectQueries();
    customerRS.startcon.connectToDB();
    while(customerRS.rs != null){

    }
    return null;
}

Code Snippet from SelectQueries.java class

public  ResultSet getCustomerByID(int intCustomerID) {
    startcon.connectToDB();
    String sql = null;
    sql = "SELECT * "
            + "FROM "
            + "h_customers ";
    try {
        st.setInt(1, intCustomerID);
        rs = st.executeQuery();         
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return rs;
}

The Table in my .fxml file that I want to populate:

<TableView fx:id="tblcustomer" prefHeight="171.0" prefWidth="600.0" BorderPane.alignment="CENTER">
     <columns>
        <TableColumn id="intCustomerID" prefWidth="75.0" text="ID" />
        <TableColumn id="vachCustomerTitle" prefWidth="75.0" text="Title" />
        <TableColumn id="vachCustomerFirstName" prefWidth="75.0" text="First Name" />
        <TableColumn id="vachCustomerSurnames" prefWidth="75.0" text="Surname" />
        <TableColumn id="dteCustomerDOB" prefWidth="75.0" text="DOB" />
        <TableColumn id="vachCustomerAddressStreet" prefWidth="75.0" text="Street Address" />
        <TableColumn id="vachCustomerAddressTown" prefWidth="75.0" text="Town" />
        <TableColumn id="vachCustomerAddressCounty" prefWidth="75.0" text="County" />
        <TableColumn id="vachCustomerAddressPostalCode" prefWidth="75.0" text="Postal Code" />
        <TableColumn id="intCustomerHomePhone" prefWidth="75.0" text="Phone (Home)" />
        <TableColumn id="intCustomerWorkPhone" prefWidth="75.0" text="Phone (Work)" />
        <TableColumn id="intCustomerMobilePhone" prefWidth="75.0" text="Phone (Mobile)" />
        <TableColumn id="vachCustomerEmail" prefWidth="75.0" text="Email" />
     </columns>
</TableView>
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
MusH
  • 85
  • 2
  • 9
  • Can you describe why you're stuck? Are you getting an error, or is the table not populating? – mjuarez Mar 14 '15 at 18:21
  • The table isn't populating – MusH Mar 14 '15 at 18:24
  • @mjuarez I'm thinking there's just one step remaining... at the while loop. I'm not sure exactly what to do at that step.... – MusH Mar 14 '15 at 18:26
  • I made the title a bit more concise and incorporated the key problem from the comments so far, removed a lot of extra indentation in code snippets to scroll less, removed a few unneeded sentences like "thanks in advance" and "code rookie", and took out the highlighting in the MySQL table just in case. – Nathan Tuggy Mar 14 '15 at 19:48
  • See if http://stackoverflow.com/questions/25651641/javafx-mysql-connection-example-please helps – James_D Mar 16 '15 at 15:19

0 Answers0