【发布时间】:2015-04-22 15:21:51
【问题描述】:
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 显示它?
患者分类如下:
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 - 感谢您的回复!我确实有一个方法,但它不允许我在 javafx 中显示它。这可能与我的表格视图有关吗? - private TableView
tableView;...目前它直接从患者对象而不是 queueTime 表中获取值... -
将结果集添加到可观察列表的代码在哪里?我也没有在 Patient 类中看到时间字段。
-
@brian 患者类中没有时间字段...我正在尝试使用时间戳-当将患者添加到我的队列中时,它们会添加到带有时间戳的数据库中,但是,我正在努力从数据库中恢复时间戳!有没有更简单的方法来做到这一点?即在患者对象中有一个时间字段?!添加了我从上面的数据库中获取结果集的方法...非常感谢!
-
CURRENT_TIMESTAMP是什么?沿着?我会发布一个小例子
标签: java database sqlite jdbc javafx