0

I have made a feedback submit page when user click on submit button it will submit using mysql jdbc connector.

I want to change text of submit button on click then it will execute sql statements after completing queries it will show submit button again. It's like a loader animation on submit button.

 public  void submitFeedback() throws SQLException, ClassNotFoundException {
------> feedbtn.setText("Submitting ...");    <-----------------------------------
        ConnectionClass connectionclass = new ConnectionClass();
        Connection connection = (Connection) connectionclass.getConnection();
        System.out.println("connection" +connection);
        star =  Math.round(rating.getRating());
        msg = feedtextarea.getText();
        name = nameinput.getText();
        email = emailinput.getText();


        String sql  = "INSERT INTO feedback(name,msg,star,email) VALUES('"+name+"','"+msg+"',"+star+",'"+email+"')";
        Statement st = connection.createStatement();
        System.out.println(sql);
        result = st.executeUpdate(sql);

        if(result == 1)
        {
            System.out.println(result);
            response.setText("Your response has been submitted !");
            rating.setRating(0.0);
            feedtextarea.setText("");
            nameinput.setText("");
            emailinput.setText("");
        }else{
            System.out.println(result);
            response.setText("Something went wrong !");
        }
        feedbtn.setText("Submit");
    }

feedbtn is id of submit button .when click on submit button it should show submitting... but it shows after execute all queries then converts to submit again very fast.

7
  • Try to add a timer to the queries to see if the queries execute to fast for your text changing to happen Commented Jun 22, 2022 at 14:16
  • 1
    You're (presumably: you would get exceptions otherwise) executing this all on the FX Application Thread. That thread is responsible for rendering the UI. Since it's busy running your database queries, it can't actually update the UI with the changes you made to the button's text until everything is completed, at which point the text is back to its original value. Commented Jun 22, 2022 at 15:00
  • @James_D Yes James, You'are correct I am getting this error . So what should I do. Commented Jun 22, 2022 at 16:05
  • See the duplicate question: it has a complete answer. Commented Jun 22, 2022 at 16:06
  • can you give link of that question if you've no problem thanks :) Commented Jun 22, 2022 at 16:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.