//JavaFXTemplate1.java package javafxtemplate1; import javafx.application.Application; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Pos; //import javafx.event.ActionEvent; //import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.ComboBox; //import javafx.scene.control.Button; //import javafx.scene.control.Label; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn.CellDataFeatures; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.util.Callback; /** * * @author Manas9 */ public class JavaFXTemplate1 extends Application { //User Interface - display @Override public void start(Stage primaryStage) throws Exception { // Group groot = new Group(); VBox groot = new VBox(); ExternalClass1 ext1 = new ExternalClass1(); ext1.loaddata();// loading data in recordset // TableView visTable = new TableView(); //creating coulmn headers TableColumn eid = new TableColumn<>("eID"); TableColumn firstNameCol = new TableColumn<>("firstName"); TableColumn lastNameCol = new TableColumn<>("lastName"); //TableColumn eAge = new TableColumn<>("eAge"); TableColumn eAge = new TableColumn<>("eAge"); //setting datatype and bind data to columns firstNameCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures p) { // p.getValue() returns the Person instance for a particular TableView row return p.getValue().firstNameProperty(); } }); //lastname lastNameCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures p) { // p.getValue() returns the Person instance for a particular TableView row return p.getValue().lastNameProperty(); } }); // eid.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures p) { // p.getValue() returns the Person instance for a particular TableView row return p.getValue().empIDProperty(); } }); // eAge.setCellValueFactory(new Callback, ObservableValue>() { public ObservableValue call(CellDataFeatures p) { // p.getValue() returns the Person instance for a particular TableView row return p.getValue().ageProperty(); } }); // // visTable.getColumns().addAll(eid, firstNameCol, lastNameCol, eAge); visTable.getItems().addAll(ext1.loaddata()); groot.getChildren().addAll(visTable); Scene scene = new Scene(groot, 350, 150); primaryStage.setScene(scene); primaryStage.setTitle("PostgreSQL:: UIControl"); primaryStage.show(); } public static void main(String[] args) { launch(args); } } // Visitor1.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javafxtemplate1; /** * * @author Manas9 */ import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.StringProperty ; import javafx.beans.property.SimpleStringProperty ; public class Visitor1 { private final StringProperty firstName; private final StringProperty lastName; private final IntegerProperty eAge; private final IntegerProperty pID; //private final DoubleProperty Salary public Visitor1(int empID,String fName, String lName, int age) { this.firstName = new SimpleStringProperty(fName); this.lastName = new SimpleStringProperty(lName); this.eAge= new SimpleIntegerProperty(age); this.pID = new SimpleIntegerProperty(empID); } // below, property name must start with param name //like empID should have empIDProperty else integer returns 0 public StringProperty firstNameProperty(){return firstName; } public StringProperty lastNameProperty(){return lastName; } public IntegerProperty ageProperty() { return eAge; } public IntegerProperty empIDProperty() { return pID; } } //ExternalClass1.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javafxtemplate1; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; /** * * @author Manas9 */ public class ExternalClass1 { public static String str1, str2, str3,str4; public int n1; // call ExtrenalClass2 prior to Externalclass1 ExternalClass2 extclass = new ExternalClass2(); private static Connection conn; public List list1 = new ArrayList(); public Listloaddata() throws SQLException { Connection connect = extclass.createConnection(); String query = " SELECT * FROM pgsvisitor1b where id=102"; Statement st = null;// query statement support ResultSet rs = null;// active connection database result st = connect.createStatement(); rs = st.executeQuery(query); List vList = new ArrayList<>(); while (rs.next()) { int eID = rs.getInt("id"); String firstName = rs.getString("fname"); String lastName = rs.getString("lname"); int eAge = rs.getInt("age"); Visitor1 person = new Visitor1(eID,firstName, lastName, eAge); vList.add(person); } return vList; } } // ExternalClass2.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javafxtemplate1; import java.sql.Connection; import java.sql.DriverManager; /** * * @author Manas9 */ public class ExternalClass2 { Connection cnn= null; String dbURL = "jdbc:postgresql://localhost:5432/pgsdemo1"; String user = "postgres"; String pwd = "postgre_manas9"; // Creating a function to get a connection public Connection createConnection() { System.out.println("Connection Object Created"); // checking connection if (cnn != null) { System.out.println("Can't creaate a connection"); return cnn; } else { try { // Getting connection cnn = DriverManager.getConnection(dbURL,user,pwd); } catch (Exception e) { System.out.println(e.toString()); } } return cnn; } }