Reputation: 31
I'm not able to populate the data from the sqlite database. It is just displaying cells n the table but there is no data. I'm new to javafx so please forgive me if there are any huge mistakes.
This is the controller class
public class ReportController implements Initializable {
//report page variables
@FXML private Label nameLabelReport;
@FXML private Label addressLabelReport;
@FXML private TextField memberIdField;
@FXML private TextField locationField;
@FXML private Button memberSearchBtn;
@FXML private Button locationSearchBtn;
//Report table variables
@FXML private TableView reportTable;
@FXML private TableColumn memberColumn;
@FXML private TableColumn nameColumn;
@FXML private TableColumn addressColumn;
@FXML private TableColumn phoneNoColumn;
@FXML private TableColumn emailColumn;
@FXML private TableColumn designationColumn;
@FXML private TableColumn siteNoColumn;
@FXML private TableColumn locationColumn;
@FXML private TableColumn sqftColumn;
@FXML private TableColumn totalAmtColumn;
@FXML private TableColumn advanceColumn;
@FXML private TableColumn toBePaidColumn;
private static Connection con;
private static Statement stat;
private PreparedStatement prep;
private static ObservableList<UserData> data;
@FXML
protected void handleReportSearch(MouseEvent event) throws IOException {
System.out.println("Entered else");
try {
con = DriverManager.getConnection("jdbc:sqlite:housing_society.db");
stat = con.createStatement();
System.out.println("Entered else");
String location;
location = locationField.getText();
System.out.println("Connected to database "+location);
ResultSet rs = con.createStatement().executeQuery("SELECT * FROM society_members WHERE site_location like '"+ location + "'");
while (rs.next()) {
UserData userData = new UserData(rs.getString("membership_id"), rs.getString("name"), rs.getString("address"), rs.getString("phone_number"), rs.getString("email"), rs.getString("working_organization"), rs.getString("designation"), rs.getString("site_no"), rs.getString("site_location"), rs.getFloat("per_square_feet_charges"),rs.getFloat("total_amount"), rs.getFloat("paid_in_advance"), rs.getFloat("to_be_paid"));
data.add(userData);
}
} catch (SQLException ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
memberColumn.setCellValueFactory(new PropertyValueFactory("membershipID") );
nameColumn.setCellValueFactory(new PropertyValueFactory("Name") );
addressColumn.setCellValueFactory(new PropertyValueFactory("address") );
phoneNoColumn.setCellValueFactory(new PropertyValueFactory("phoneNo") );
emailColumn.setCellValueFactory(new PropertyValueFactory("email") );
designationColumn.setCellValueFactory(new PropertyValueFactory("designation") );
siteNoColumn.setCellValueFactory(new PropertyValueFactory("siteNo") );
locationColumn.setCellValueFactory(new PropertyValueFactory("location") );
sqftColumn.setCellValueFactory(new PropertyValueFactory("perSqFt") );
totalAmtColumn.setCellValueFactory(new PropertyValueFactory("totalAmt") );
advanceColumn.setCellValueFactory(new PropertyValueFactory("paidInAdvance") );
toBePaidColumn.setCellValueFactory(new PropertyValueFactory("toBePaid") );
data = FXCollections.observableArrayList();
reportTable.setItems(data);
}
private static class UserData {
public StringProperty membershipID;
public StringProperty Name;
public StringProperty address;
public StringProperty phoneNo;
public StringProperty email;
public StringProperty workingOrganization;
public StringProperty designation;
public StringProperty siteNo;
public StringProperty location;
public FloatProperty perSqFt;
public FloatProperty totalAmt;
public FloatProperty paidInAdvance;
public FloatProperty toBePaid;
public UserData(String membershipID, String Name, String address,String phoneNo, String email, String workingOrganization, String designation, String siteNo, String location, float perSqFt, float totalAmt, float paidInAdvance, float toBePaid) {
this.membershipID = new SimpleStringProperty(membershipID);
this.Name = new SimpleStringProperty(Name);
this.address = new SimpleStringProperty(address);
this.phoneNo = new SimpleStringProperty(phoneNo);
this.email = new SimpleStringProperty(email);
this.workingOrganization = new SimpleStringProperty(workingOrganization);
this.designation = new SimpleStringProperty(designation);
this.location = new SimpleStringProperty(location);
this.siteNo = new SimpleStringProperty(siteNo);
this.perSqFt = new SimpleFloatProperty(perSqFt);
this.totalAmt = new SimpleFloatProperty(totalAmt);
this.paidInAdvance = new SimpleFloatProperty(paidInAdvance);
this.toBePaid = new SimpleFloatProperty(toBePaid);
}
public StringProperty getMembershipID() {
return membershipID;
}
public StringProperty getName() {
return Name;
}
public StringProperty getAddress() {
return address;
}
public StringProperty getPhoneNo() {
return phoneNo;
}
public StringProperty getEmail() {
return email;
}
public StringProperty getWorkingOrganization() {
return workingOrganization;
}
public StringProperty getDesignation() {
return designation;
}
public StringProperty getSiteNo() {
return siteNo;
}
public StringProperty getLocation() {
return location;
}
public FloatProperty getPerSqFt() {
return perSqFt;
}
public FloatProperty getTotalAmt() {
return totalAmt;
}
public FloatProperty getPaidInAdvance() {
return paidInAdvance;
}
public FloatProperty getToBePaid() {
return toBePaid;
}
}
}
I will not include the FXML file because it will make this question very big and complicated.I will just the add the lines which are necessary.
Link to controller
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="postalhs.ReportController">
This is the button tag. When clicked will call handleReportSearch
method
<Button onMouseClicked="#handleReportSearch" fx:id="locationSearchBtn" layoutX="344.0" layoutY="172.0" mnemonicParsing="false" text="Search" />
TableView
<TableView fx:id="reportTable" prefHeight="238.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<columns>
<TableColumn fx:id="memberColumn" prefWidth="93.0" text="Membership ID" />
<TableColumn fx:id="nameColumn" prefWidth="57.0" text="Name" />
<TableColumn fx:id="addressColumn" prefWidth="60.0" text="Address" />
<TableColumn fx:id="phoneNoColumn" prefWidth="90.0" text="Phone Number" />
<TableColumn fx:id="emailColumn" prefWidth="69.0" text="Email" />
<TableColumn fx:id="designationColumn" prefWidth="81.0" text="Designation" />
<TableColumn fx:id="siteNoColumn" prefWidth="75.0" text="Site Number" />
<TableColumn fx:id="locationColumn" prefWidth="75.0" text="Site Location" />
<TableColumn fx:id="sqftColumn" prefWidth="75.0" text="Per square feet charges" />
<TableColumn fx:id="totalAmtColumn" prefWidth="75.0" text="Total Amount" />
<TableColumn fx:id="advanceColumn" prefWidth="75.0" text="Paid in Advance" />
<TableColumn fx:id="toBePaidColumn" prefWidth="75.0" text="To Be Paid" />
</columns>
</TableView>
Upvotes: 1
Views: 154
Reputation: 1938
JavaFX 8 may be different, but JavaFX 2 requires Property
methods to be reflective in order to successfully bind with a value. Modify your current UserData class methods (or add new ones) that meet the Property
method convention (i.e. "Property()").
Like this:
public StringProperty membershipIDProperty() {
return membershipID;
}
Upvotes: 1