我对javafx和jdbc都是陌生的。我正在一个需要构建从头开始的项目(我选择了javafx)来显示数据和检索数据。以上是我的尝试,但没有成功。在我输入任何jdbc代码之前,它可以完美地工作。请帮忙
如何从MySQL检索数据并使用javafx显示数据 在这种情况下,如何进行计算结束日期-开始结束以获取持续时间 如何处理不同的类型,例如在javafx的Text Object中显示int
假设所有需求导入均已导入,并假设在没有jdbc代码的情况下它可以完美工作
错误消息太长了,所以我只在这里列出一些 应用程序启动方法异常 由以下原因引起:java.sql.SQLException:结果集开始之前
public class C32 extends Application {
String stm = "select * from e_vent where sitename = 'Atlanta BeltLine Center'";
String stm2 = "select datediff(end_date, start_date) as duratoin from e_vent";
@Override
public void start(Stage SED) throws Exception {
GridPane gp = new GridPane();
gp.setAlignment(Pos.CENTER);
Text event = new Text("Event: ");
gp.add(event, 0, 1);
Text eventT = new Text(getResult(stm).getString("event_name"));
gp.add(eventT, 1, 1);
Text site = new Text("Site: ");
gp.add(site, 4, 1);
Text siteT = new Text(getResult(stm).getString("sitename"));
gp.add(siteT, 5, 1);
Text startD = new Text("Start Date: ");
gp.add(startD, 0, 2);
Date date = getResult(stm).getDate("start_date");
Text startDT = new Text(date.toString());
gp.add(startDT, 1, 2);
Text endD = new Text("End Date: ");
gp.add(endD, 2, 2);
Date date2 = getResult(stm).getDate("end_date");
Text endDT = new Text(date2.toString());
gp.add(endDT, 3, 2);
Text durationD = new Text("Duration Day: ");
gp.add(durationD, 4, 2);
Integer test = getResult(stm2).getInt("duration");
Text durationDT = new Text(test.toString());
gp.add(durationDT, 5, 2);
Text staffA = new Text("Staff Assigned: ");
gp.add(staffA, 0, 3);
Text staffAT = new Text("_");
gp.add(staffAT, 1, 3);
Text capacity = new Text("Capacity: ");
gp.add(capacity, 2, 3);
Integer c1 = getResult(stm).getInt("capacity");
Text capacityT = new Text(c1.toString());
gp.add(capacityT, 3, 3);
Text price = new Text("Price: ");
gp.add(price, 4, 3);
Double p1 = getResult(stm).getDouble("event_price");
Text priceT = new Text(p1.toString());
gp.add(priceT, 5, 3);
Text description = new Text("Description: ");
gp.add(description, 0, 4);
Text descriptionT = new Text(getResult(stm).getString("descript"));
gp.add(descriptionT, 1, 4);
bp.getChildren().add(gp);
}
public static void main(String args[]) {
launch(args);
}
public static ResultSet getResult(String a) {
ResultSet rs = null;
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/atlanta_beltlinetest?"
+ "allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC", "root", "Destiny123");
Statement stmt = con.createStatement();
String sql = a;
rs = stmt.executeQuery(sql);
System.out.println("all good");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}