0

I've been working on JavaFX app for some archive, I made a simple user interface app with add, edit, delete, update and search methods, the app works fine, the MySQL database is correctly connected and the methods are being applied correctly my one issue is the Tableview in my app is blank, not showing the data in my database here is the code of my controller class:

        @FXML
    private TableView<users> table_users;

    @FXML
    private TableColumn<users, Integer> col_id;

    @FXML
    private TableColumn<users, String> col_username;

    @FXML
    private TableColumn<users, String> col_napel;

    @FXML
    private TableColumn<users, String> col_nserie;

    @FXML
    private TableColumn<users, String> col_fc;

    @FXML
    private TableColumn<users, String> col_nc;

    @FXML
    private TableColumn<users, String> col_du;

    @FXML
    private TableColumn<users, String> col_ms;

    @FXML
    private TableColumn<users, String> col_gp;

    @FXML
    private TableColumn<users, String> col_pw;

    @FXML
    private TextField filterField;


ObservableList<users> listM;
ObservableList<users> dataList;

int index = -1;

Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;



@Override
public void initialize(URL url, ResourceBundle rb) {
    
    col_id.setCellValueFactory(new PropertyValueFactory<users,Integer>("id")); 
    col_username.setCellValueFactory(new PropertyValueFactory<users,String>("username")); 
    col_napel.setCellValueFactory(new PropertyValueFactory<users,String>("napel")); 
    col_nserie.setCellValueFactory(new PropertyValueFactory<users,String>("nserie"));
    col_fc.setCellValueFactory(new PropertyValueFactory<users,String>("fc"));
    col_nc.setCellValueFactory(new PropertyValueFactory<users,String>("nc"));
    col_du.setCellValueFactory(new PropertyValueFactory<users,String>("du"));
    col_ms.setCellValueFactory(new PropertyValueFactory<users,String>("ms"));
    col_gp.setCellValueFactory(new PropertyValueFactory<users,String>("gp"));
    col_pw.setCellValueFactory(new PropertyValueFactory<users,String>("pw"));
     

    listM = mysqlConnect.getDatausers();
    table_users.setItems(listM);
    UpdateTable();
    search_user();
}

}

here is the code on my constructor class:

public class users {
int id;
String username, napel, nserie, fc, nc, du, ms, gp, pw;
public users(int id, String username, String napel, String nserie, String fc, String nc, String du, String ms,
        String gp, String pw) {
    super();
    this.id = id;
    this.username = username;
    this.napel = napel;
    this.nserie = nserie;
    this.fc = fc;
    this.nc = nc;
    this.du = du;
    this.ms = ms;
    this.gp = gp;
    this.pw = pw;

//the setters and getters are pretty straightforward
}

and here is the database related part of connection class :

   public static ObservableList<users> getDatausers(){
    Connection conn = ConnectDb();
    ObservableList<users> list = FXCollections.observableArrayList();
    try {
        PreparedStatement ps = conn.prepareStatement("select * from users");
        ResultSet rs = ps.executeQuery();
        
        while (rs.next()){   
            list.add(new users(Integer.parseInt(rs.getString("id")), rs.getString("username"), rs.getString("napel"), rs.getString("nserie"), rs.getString("fc"), rs.getString("nc"), rs.getString("du"), rs.getString("ms"), rs.getString("gp"), rs.getString("pw")));               
        }
    } catch (Exception e) {
    }
    return list;
}
Lyly
  • 15
  • 4
  • hello everyone, I am new to this, so please if there is anything I can do to my make the question clear or to clarify more, feel free to ask and bear with my beginner attitude, thank you. –  Lyly Oct 04 '20 at 08:31
  • being new requires to work through tutorials/help pages, doesn't it :) Here that mean: a) learn how to use TableView b) stick to java naming conventions (not doing so for the properties of your data object is the most probable reason for the problem, see the duplicate) c) provide a [mcve] - that is a minimal example written for the exclusive use to demonstrate what's wrong: it must be comileable/runnable without any change d) read a site's help pages before posting :) – kleopatra Oct 04 '20 at 09:57
  • @kleopatra, you are right, i am trying to learn as much as possible, this app came straight from a tutorial, i just changed some of the parametres and columns, dealing with the errors that came along the way, this reason i posted, is because i got confused, even thogh i didn't deviate much from the original app, it refused to show data on the table but i'll keep in mind your advice in the near future, thank you. –  Lyly Oct 04 '20 at 10:37
  • compare the _just changed some_ in the original and yours, look at a single one at a time, write an example just containing that single difference .. you'll see _exactly_ what went wrong :) – kleopatra Oct 04 '20 at 10:41

0 Answers0