这是我从MS SQL数据库加载数据的方法
public <SUPER super T> T from(SUPER fromInstance);
这是类客户,它引用了上一个类
private void LoadTable() {
try {
//making connections
conn = MakeConnection();
ResultSet rs = conn.createStatement().executeQuery(QueryString);
//populating the Observable List
while(rs.next()){
data.add(new Customer(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getInt(9),rs.getString(10),rs.getDouble(11),rs.getDouble(12)));
}
colID.setCellValueFactory(new PropertyValueFactory<>("CustomerID"));
colFName.setCellValueFactory(new PropertyValueFactory<>("FName"));
colMName.setCellValueFactory(new PropertyValueFactory<>("MName"));
colLName.setCellValueFactory(new PropertyValueFactory<>("LName"));
colEmail.setCellValueFactory(new PropertyValueFactory<>("Email"));
colMobile.setCellValueFactory(new PropertyValueFactory<>("Mobile"));
colAddress.setCellValueFactory(new PropertyValueFactory<>("Address"));
colCity.setCellValueFactory(new PropertyValueFactory<>("City"));
colZip.setCellValueFactory(new PropertyValueFactory<>("Zip"));
colState.setCellValueFactory(new PropertyValueFactory<>("State"));
colCredit.setCellValueFactory(new PropertyValueFactory<>("Credit"));
colDeposit.setCellValueFactory(new PropertyValueFactory<>("Deposit"));
tableManageCustomer.setItems(data);
} catch (SQLException ex) {
System.out.println(ex.toString());
}
}
Coonection工作正常,因为我使用System.out.println()检查它并从数据库中获取了正确的值,但是当我在读取ResultSet时启动类Customer的构造函数(即,在此处命名为rs)时,它给出了以下异常
public class Customer {
private final IntegerProperty CustomerID;
private final StringProperty FName;
private final StringProperty MName;
private final StringProperty LName;
private final StringProperty Email;
private final StringProperty Mobile;
private final StringProperty Address;
private final StringProperty City;
private final IntegerProperty Zip;
private final StringProperty State;
private final DoubleProperty Credit;
private final DoubleProperty Deposit;
public Customer(Integer CustomerID, String FName, String MName, String LName, String Email, String Mobile, String Address, String City, Integer Zip, String State, Double Credit, Double Deposit){
this.CustomerID=new SimpleIntegerProperty(CustomerID);
this.FName=new SimpleStringProperty(FName);
this.MName=new SimpleStringProperty(MName);
this.LName=new SimpleStringProperty(LName);
this.Email=new SimpleStringProperty(Email);
this.Mobile=new SimpleStringProperty(Mobile);
this.Address=new SimpleStringProperty(Address);
this.City=new SimpleStringProperty(City);
this.Zip=new SimpleIntegerProperty(Zip);
this.State=new SimpleStringProperty(State);
this.Credit=new SimpleDoubleProperty(Credit);
this.Deposit=new SimpleDoubleProperty(Deposit);
}
//All Getters
public IntegerProperty getCustomerID() {
return CustomerID;
}
public StringProperty getFName() {
return FName;
}
public StringProperty getMName() {
return MName;
}
public StringProperty getLName() {
return LName;
}
public StringProperty getEmail() {
return Email;
}
public StringProperty getMobile() {
return Mobile;
}
public StringProperty getAddress() {
return Address;
}
public StringProperty getCity() {
return City;
}
public IntegerProperty getZip() {
return Zip;
}
public StringProperty getState() {
return State;
}
public DoubleProperty getCredit() {
return Credit;
}
public DoubleProperty getDeposit() {
return Deposit;
}
//All Setters
public void setCustomerID(Integer Value){
CustomerID.set(Value);
}
public void setFName(String Value){
FName.set(Value);
}
public void setMName(String Value){
MName.set(Value);
}
public void setLName(String Value){
LName.set(Value);
}
public void setEmail(String Value){
Email.set(Value);
}
public void setMobile(String Value){
Mobile.set(Value);
}
public void setAddress(String Value){
Address.set(Value);
}
public void setCity(String Value){
City.set(Value);
}
public void setZip(Integer Value){
Zip.set(Value);
}
public void setState(String Value){
State.set(Value);
}
public void setCredit(Double Value){
Credit.set(Value);
}
public void setDeposit(Double Value){
Deposit.set(Value);
}
//Property Values
public IntegerProperty CustomerIDProperty(){
return CustomerID;
}
public StringProperty FNameProperty(){
return FName;
}
public StringProperty MNameProperty(){
return MName;
}
public StringProperty LNameProperty(){
return LName;
}
public StringProperty EmailProperty(){
return Email;
}
public StringProperty MobileProperty(){
return Mobile;
}
public StringProperty AddressProperty(){
return Address;
}
public StringProperty CityProperty(){
return City;
}
public IntegerProperty ZipProperty(){
return Zip;
}
public StringProperty StateProperty(){
return State;
}
public DoubleProperty CreditProperty(){
return Credit;
}
public DoubleProperty DepositProperty(){
return Deposit;
}
}