При запуске формы никаких ошибок не выводится, но метод 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;
}
}
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Подскажите пожалуйста, как исправить ошибку при переходе на фрейм ошибкаКак можно при нажатии на кнопку перейти на другую вкладку? Браузер...
Исходные данные: файл, с одной единственной колонкой, в которой находятся числа от 0 до IntegerMAX_INT
Как видно, оба элемента делают одно и тоже, как объединить этот код, чтобы красиво смотрелось и читалось
Объясните, пожалуйста, почему, если я буду нажимать следующие клавиши по очереди: {a,enter,b,enter,q, enter}, то я увижу ужасно странный вывод, который...