package javafxtemplate1; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class JavaFXTemplate1 extends Application { Label caption1 = new Label("Output Label :: Events Name"); Label caption2 = new Label("OutPut Label :: from show_tex1()"); String fxstr1=null; @Override public void start(Stage primaryStage)throws SQLException { System.out.println("main block executing "); //JDBC PostgreSQL Connection c = null; //manage copnnection Statement st = null;// query statement support ResultSet rs = null;// active connection database result String dbURL = "jdbc:postgresql://localhost:5432/pgsdemo1"; String user = "postgres"; String pwd = "postgre_manas9"; String query = " select show_text1() "; //try catch Block try { // Connection>>statement >> Resultset >> c = DriverManager.getConnection(dbURL,user,pwd); st = c.createStatement(); rs = st.executeQuery(query); fxstr1 = Process.loaddata(rs); System.out.println(fxstr1); } catch (SQLException ex) { ex.getErrorCode(); String message = ex.getMessage(); System.out.println(message); } finally { System.out.println("going through final block"); try { if (st== null || st.isClosed()) { } else { st.close(); } if (c != null && !c.isClosed()) { c.close(); } } catch (SQLException ex) { ex.getErrorCode(); ex.getMessage(); } } System.out.println("dis-Connected to database successfully"); //JavaFX Controls BorderPane root = new BorderPane(); Button ctrlbtn = new Button("Click Me"); Scene scene = new Scene(root,300,250); ctrlbtn.setOnAction(e->ctrlbutton_click()); GridPane gPane = new GridPane(); gPane.setAlignment(Pos.CENTER); gPane.setHgap(10);gPane.setVgap(15); gPane.add(caption1, 0, 0); gPane.add(caption2, 0, 1); gPane.add(ctrlbtn, 0, 2); root.setCenter(gPane); primaryStage.setTitle(this.fxstr1); primaryStage.setScene(scene); primaryStage.show(); } public void ctrlbutton_click() { caption1.setText("Button Clicked " ); caption2.setText(fxstr1 ); } public static void main(String[] args) throws SQLException { launch(args); } } class Process { private static String str1; public static String str3= null; public static String loaddata(ResultSet rs) throws SQLException { try { while(rs.next()) { str1 = rs.getString(1); // will have "Hello World" Text } str3 = str1; } catch (Exception e) { System.out.println(e.toString()); } return str3; } }