Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package tabledemo;
- import java.net.URL;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ResourceBundle;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Label;
- import javafx.scene.control.TableColumn;
- import javafx.scene.control.TableView;
- import javafx.scene.control.cell.PropertyValueFactory;
- /**
- *
- * @author User
- */
- public class SampleController implements Initializable {
- @FXML public TableView displayDepartments;
- @FXML public TableColumn deptNameCol;
- @FXML public TableColumn cityCol;
- @FXML public TableColumn townCol;
- @FXML public TableColumn phoneCol;
- @FXML public TableColumn addressCol;
- @FXML public TableColumn emailCol;
- public ObservableList data;
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- deptNameCol.setCellValueFactory(new PropertyValueFactory<Department, Department>("deptN"));
- cityCol.setCellValueFactory(new PropertyValueFactory<Department, String>("cityN"));
- townCol.setCellValueFactory(new PropertyValueFactory<Department, String>("townN"));
- phoneCol.setCellValueFactory(new PropertyValueFactory<Department, String>("townN"));
- addressCol.setCellValueFactory(new PropertyValueFactory<Department, String>("addressN"));
- emailCol.setCellValueFactory(new PropertyValueFactory<Department, String>("emailN"));
- populateDepartmentTable();
- }
- @SuppressWarnings("unchecked")
- public void populateDepartmentTable(){
- String SQL = "select deptName, city, town, phone, address, email from departments where town='westlands'";
- data = FXCollections.observableArrayList();
- DBConnections db = new DBConnections();
- Connection conn;
- int k =0;
- try{
- conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(SQL);
- // System.out.print(SQL);
- int sum=0;
- while(rs.next()){
- ObservableList<String> row = FXCollections.observableArrayList();
- for(int i=1; i<rs.getMetaData().getColumnCount()+1; i++){
- row.add(rs.getString(i));
- }
- System.out.println("row["+(k += 1)+"]"+row);
- data.add(row);
- }
- //displayDepartments.setItems(data);
- displayDepartments.getItems().addAll(data);
- System.out.println(data);
- }
- catch(Exception ex){
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement