我有一个试图从使用sql数据库创建的查询中填充的表格视图。其中一列包含一个日期值,当我运行该程序时,出现一个错误,提示“ com.microsoft.sqlserver.jdbc.SQLServerException:列名AppointmentDate无效。”这是我的一些代码。
HoustonAppointments.java
//Set variable
java.util.Date AppointmentDate;
//Constructor
public HoustonAppointments(Date appointmentDate) {
AppointmentDate = appointmentDate;
}
//Getter and setter
public java.util.Date getAppointmentDate() {
return AppointmentDate;
}
public void setAppointmentDate(java.util.Date appointmentDate) {
AppointmentDate = appointmentDate;
}
控制器类
public class HoustonAppointmentsController implements Initializable {
//Connect control from FXML
@FXML TableColumn<HoustonAppointments, Date> AppointmentDate;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
//Set cell value factory
AppointmentDate.setCellValueFactory(new PropertyValueFactory<>("AppointmentDate"));
//Query function
try{
ResultSet rs = statement.executeQuery("SELECT Customer.FirstName, Customer.LastName,
City.CityName, Appointments.AppointmentDate as 'Appointment Date'\n" +
"FROM Orders INNER JOIN\n" +
"Customer ON Orders.CustomerID = Customer.CustomerID INNER JOIN\n" +
"ShootLocation ON Orders.LocationID = ShootLocation.LocationID INNER JOIN\n" +
"City INNER JOIN\n" +
"CityState ON City.CityID = CityState.CityID ON ShootLocation.CityStateID =
CityState.CityStateID INNER JOIN\n" +
"Appointments ON Customer.CustomerID = Appointments.CustomerID AND
ShootLocation.LocationID = Appointments.LocationID\n" +
"Where CityName = 'Houston'\n" +
"Order by Appointments.AppointmentDate desc");
while(rs.next()){
shootsObservableList.add(new HoustonAppointments(rs.getDate("AppointmentDate")));
}
conn.close();
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
houstonShootsTableView.setItems(shootsObservableList);
}
}