Skip to content

Get Current logged User Id and User Name using JavaFX

I’m trying to create an application using JavaFX. I want to get current logged userid and username, after successful login. I want to display it is in the home page. How can i do this? please help

    private Label tf_getname;

    void happyButton(ActionEvent event) {

        DbConnect dbconnect=new DbConnect();
        Connection conn=dbconnect.getConnection();

        String username = tf_getname.getText();

//        String source1 = event.getSource().toString(); //yields complete string
        //String source2 = event.getPickResult().getIntersectedNode().getId(); //returns JUST the id of the object that was clicked
//        System.out.println("Full String: " + source1);
//        System.out.println("Just the id: " + source2);
//        System.out.println(" " + source2);

        try {

            String sql = "SELECT name FROM users WHERE name='"+username+"'";

            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);



        } catch (Exception e) {



I think there is something wrong with your statement. Try out the following way to set up and execute a Statement.

Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("Select * from test");
        }catch(Exception e){