I'm still a noob in JavaFX, I can print the content of the table that I query, the problem is that I want the content to be placed inside the tableview. This is the code that I have done.

public class TableViewController  implements Initializable{

private TableView<studentInfo> tblViewer = new TableView();
private TableColumn colID = new TableColumn();
private TableColumn colName = new TableColumn();
private TableColumn colAddress = new TableColumn();
private TableColumn colAge = new TableColumn();
private TableColumn colContact = new TableColumn();
private Button cmdTest;

public void initialize(URL url, ResourceBundle rb) {
    // TODO
    System.out.println(this.getClass().getSimpleName() + ".initialize"); 
    cmdTest.setOnAction(new EventHandler<ActionEvent>() {            
            public void handle(ActionEvent event) {
                System.out.println("Button Pressed");

                colID.setCellValueFactory(new PropertyValueFactory<studentInfo, Integer>("id"));
                colName.setCellValueFactory(new PropertyValueFactory<studentInfo, String>("name"));
                colAddress.setCellValueFactory(new PropertyValueFactory<studentInfo, String>("address"));
                colAge.setCellValueFactory(new PropertyValueFactory<studentInfo, Integer>("age"));
                colContact.setCellValueFactory(new PropertyValueFactory<studentInfo, String>("contact_num"));
        } );       

public class studentInfo{

    private final SimpleIntegerProperty idCol;
    private final SimpleStringProperty nameCol;
    private final SimpleStringProperty addressCol;
    private final SimpleIntegerProperty ageCol;
    private final SimpleStringProperty contact_numCol;

    public studentInfo(Integer id, String name, String address, Integer age, String contact_num){
        this.idCol = new SimpleIntegerProperty(id);
        this.nameCol = new SimpleStringProperty(name);
        this.addressCol = new SimpleStringProperty(address);
        this.ageCol = new SimpleIntegerProperty(age);
        this.contact_numCol = new SimpleStringProperty(contact_num);
      public Integer getidCol(){
          return idCol.get();
      public void setidCol(Integer id){
      public String getnameCol(){
          return nameCol.get();
      public void setnameCol(String name){
      public String getaddressCol(){
          return addressCol.get();
      public void setaddressCol(String address){
      public Integer getageCol(){
          return ageCol.get();
      public void setageCol(Integer age){
      public String getcontact_numCol(){
          return contact_numCol.get();
      public void setcontact_numCol(String contact_num){

//public static ObservableList<COA> getAllCOA(){
public List<studentInfo> getAllstudentInfo(){
    Connection conn;
    List ll = new LinkedList();
    Statement st;
    ResultSet rs;
    String url = "jdbc:mysql://localhost/java_test";
    String user = "root";
    String pass = "";
    String driver = "com.mysql.jdbc.Driver";

        conn = DriverManager.getConnection(url, user, pass);
        st = conn.createStatement();
        String recordQuery = ("Select * from student");            
        rs = st.executeQuery(recordQuery);
            Integer id = rs.getInt("id");
            String name = rs.getString("name");
            String address = rs.getString("address");
            Integer age = rs.getInt("age");
            String contact_num = rs.getString("contact_num");

            ll.add(new studentInfo(id, name, address, age, contact_num));
            System.out.println(id +","+ name +","+ address +","+ age +","+ contact_num +" "+"added.");
    }catch(ClassNotFoundException | SQLException ex){
        Logger.getLogger(TableViewController.class.getName()).log(Level.SEVERE, null, ex);
    return ll;        

Please help me.

Recommended Answers

and what does this have to do with Java?

Jump to Post

All 3 Replies

and what does this have to do with Java?

ahm.its for javafx. I wanted to populate a table.

i am getting error in rs = st.executeQuery(recordQuery);
please fix this thanks for solve in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.