Не отображаются данные в таблице TableView

172
30 июня 2018, 14:40

При запуске формы никаких ошибок не выводится, но метод getDoctors() в какой-то момент начинает работать с пустотой, и, думаю, поэтому таблица не заполняется, хотя запрос правильный.

FXML:

@FXML
private void initialize () {
    try {
        doct_id.setCellValueFactory(cellData -> cellData.getValue().getDoctId().asObject());
        doc_name.setCellValueFactory(cellData -> cellData.getValue().getDoctName());
        doc_address.setCellValueFactory(cellData -> cellData.getValue().getDoctAddress());
        doc_phone.setCellValueFactory(cellData -> cellData.getValue().getDoctPhone());
        doc_salary.setCellValueFactory(cellData -> cellData.getValue().getDoctSalary().asObject());
        System.out.println("everything is OK there ");
        ObservableList<Doctors> data = DbLogic.getDoctors();
        doct_table.setItems(data);
    } catch (SQLException  | ClassNotFoundException e) {
        Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, e);
    }
}

SQL:

public static ObservableList<Doctors> getDoctors() throws SQLException, ClassNotFoundException {
    String sql = "select * from doctors";
    ResultSet rSet = null;
    try {
        rSet = DBUtil.dbExecute(sql);
    } catch (SQLException e) {
        System.out.println("smth went wrong while get records from server "+e);
        e.printStackTrace();
        throw e;
    }
    try {
        ObservableList<Doctors> doclist = FXCollections.observableArrayList();
        while (rSet.next()){
          int id = rSet.getInt("ID");
          String name = rSet.getString("NAME");
            String phone = rSet.getString("PHONE");
            String address = rSet.getString("ADDRESS");
            int salary = rSet.getInt("SALARY");
            System.out.println("id "+id+" "+name+" "+phone+""+salary+"");
            doclist.add(new Doctors(id, name,  phone, address, salary));
        }
        return doclist;
    } catch (SQLException ex){
        System.out.println("smth went wrong while load data from table "+ex);
        ex.printStackTrace();
        throw ex;
    }
}

DBUtil:

public static ResultSet dbExecute (String sqlQuery) throws SQLException, ClassNotFoundException {
    Statement stmt = null;
    ResultSet rs = null;
    try (CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet()) {
        try {
            dbConnect();
            stmt = connection.createStatement();
            rs = stmt.executeQuery(sqlQuery);
            crs.populate(rs);
        } catch (SQLException e) {
            System.out.println("smth went wrong in dbExecute! " + e);
            throw e;
        } finally {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            dbDisconnect();
        }
        return crs;
    }
}

Doctors:

public class Doctors {
private IntegerProperty idProperty;
private StringProperty nameProperty;
private StringProperty phoneProperty;
private StringProperty addressProperty;
private IntegerProperty salaryProperty;
public Doctors (int id, String name, String phone, String address, int salary) {
    this.idProperty = new SimpleIntegerProperty(id);
    this.nameProperty = new SimpleStringProperty(name);
    this.phoneProperty = new SimpleStringProperty(phone);
    this.addressProperty = new SimpleStringProperty(address);
    this.salaryProperty = new SimpleIntegerProperty(salary);
}
public int getDocId () {
    return idProperty.get();
}
public void setDocId(int id) {
    this.idProperty.set(id);
}
public IntegerProperty getDoctId() {
    return idProperty;
}
public String getDocName () {
    return nameProperty.get();
}
public void setDocName(String name) {
    this.nameProperty.set(name);
}
public StringProperty getDoctName() {
    return nameProperty;
}
public int getDocSalary () {
    return salaryProperty.get();
}
public void setDocSalary(int salary) {
    this.idProperty.set(salary);
}
public IntegerProperty getDoctSalary() {
    return salaryProperty;
}
public String getDocAddress () {
    return addressProperty.get();
}
public void setDocAddress(String address) {
    this.addressProperty.set(address);
}
public StringProperty getDoctAddress() {
    return addressProperty;
}
public String getDocPhone () {
    return phoneProperty.get();
}
public void setDocPhone(String phone) {
    this.phoneProperty.set(phone);
}
public StringProperty getDoctPhone() {
    return phoneProperty;
}

}

READ ALSO
Selenium Webdriver. При переходе на frame ошибка NoSuchFrameException

Selenium Webdriver. При переходе на frame ошибка NoSuchFrameException

Подскажите пожалуйста, как исправить ошибку при переходе на фрейм ошибкаКак можно при нажатии на кнопку перейти на другую вкладку? Браузер...

171
Как посчитать сложность алгоритма?

Как посчитать сложность алгоритма?

Исходные данные: файл, с одной единственной колонкой, в которой находятся числа от 0 до IntegerMAX_INT

235
Как объединить 2 интерфейса?

Как объединить 2 интерфейса?

Как видно, оба элемента делают одно и тоже, как объединить этот код, чтобы красиво смотрелось и читалось

200
Не понимаю как передаются байты с консоли в программу

Не понимаю как передаются байты с консоли в программу

Объясните, пожалуйста, почему, если я буду нажимать следующие клавиши по очереди: {a,enter,b,enter,q, enter}, то я увижу ужасно странный вывод, который...

208