2
public static void addToQueueTable(Patient p) {
try {
// open connection to database
conn = ConnectionFactory.getConnection();
// create statement
stmt = conn.createStatement();
String sql = "insert into queueTime values('" + p.getNhsNumber()
+ "', CURRENT_TIMESTAMP)";
// execute update
stmt.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error on Building Data");
} finally {
// close all open resources in the database
DbUtil.close(stmt);
DbUtil.close(conn);
}
}
以上是我的代码,以添加细节(NhsNumber和当前时间戳)到我的数据库 - 只是想知道我是如何显示这个使用javafx?
Patient类如下:如何将信息添加到sqlite数据库,然后使用javafx显示信息?
public Patient(String nhsNumber, String firstName,
String lastName, String postCode) {
super(nhsNumber,firstName, lastName
, postCode);
}
使用JavaFX我能显示某些细节(见下文),但我不知道我怎样才能时间戳从数据库返回的呢?任何帮助将不胜感激!
public class QueueTabPageController implements Initializable {
@FXML
private TableView<Patient> tableView;
@FXML
private TableColumn<Patient, String> firstNameColumn;
@FXML
private TableColumn<Patient, String> lastNameColumn;
@FXML
private TableColumn<Patient, String> postCodeColumn;
@FXML
private QueueTabPageController queueTabPageController;
private ObservableList<Patient> tableData;
// public static LinkedList<Patient> displayQueue;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
assert tableView != null : "fx:id=\"tableView\" was not injected: check your FXML file 'FXMLQueueTabPage.fxml'";
firstNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("firstName"));
lastNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("lastName"));
postCodeColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("postCode"));
}
@FXML
private void btnRefreshQueueClick(ActionEvent event) throws IOException{
displayQueue(Queue.queue);
}
public void displayQueue(LinkedList<Patient> queue) {
tableData = FXCollections.observableArrayList(queue);
tableView.setItems(tableData);
}
}
// open connection to database
conn = ConnectionFactory.getConnection();
// create statement
stmt = conn.createStatement();
// result set to pull information from database
ResultSet rs = stmt
.executeQuery("select * from queueTime where NHSNumber = '"
+ p.getNhsNumber() + "'");
while (rs.next()) {
// convert timestamp to String
String ts = rs.getString("Timestamp");
// print result set
System.out.print(ts + "\t");
我看不出有任何疑问?某处你需要'ResultSet rs = stmt.executeQuery(“SELECT * FROM queueTime”);' – brian
@brian - 谢谢你的回复!我确实有这样的方法,但它不让我在javafx中显示它。这可能与我的tableview有关吗? - private TableView tableView; ...目前它直接从患者对象取值,而不是queueTime表... –
Davidaj
将结果集添加到可观察列表的代码在哪里?我也没有看到Patient类中的时间字段。 – brian