我正在尝试在ListView上显示所选ID的所有记录,但是如何在Hibernate中显示来自“name”列中所选ID的记录?在MySQL中它看起来像这样,它工作正常:
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String idvalue) {
try {
pst = con.prepareStatement("SELECT * FROM przychodniadb.patient WHERE idpatient=" + idvalue);
rs = pst.executeQuery();
while (rs.next()) {
infoPIDField.setText(rs.getString(1));
infonameField.setText(rs.getString(2));
infolastNameField.setText(rs.getString(3));
infogenderField.setText(rs.getString(4));
infoageField.setText(rs.getString(5));
infophonenumberField.setText(rs.getString(6));
infoadressField.setText(rs.getString(7));
infodiseaseField.setText(rs.getString(8));
infoconditionField.setText(rs.getString(9));
infodataField.setText(rs.getString(12));
infoRoomNumber.setText(rs.getString(13));
infoRoomType.setText(rs.getString(10));*/
}
} catch (SQLException e) {
e.printStackTrace();
}
}
});
现在在Hibernate:
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String idvalue) {
Query query3 = entityManager.createQuery("FROM Patient WHERE idpatient=:idpatient");
query3.setParameter("idpatient", idvalue);
infoPIDField.setText(???);
infonameField.setText(???);
infolastNameField.setText(???);
...........
});
我应该把什么作为参数?
答案 0 :(得分:2)
首先在Patient
对象中取结果:
Patient c = (Patient) query.getSingleResult();
此后,您可以使用简单的getter访问这些字段。
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String idvalue) {
Query query3 = entityManager.createQuery("FROM Patient WHERE idpatient=:idpatient");
query3.setParameter("idpatient", idvalue);
Patient p = (Patient) query.getSingleResult();
infoPIDField.setText(p.getPIDField());
infonameField.setText(p.getNameField());
infolastNameField.setText(p.getLastNameField());
...........
}