Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7084891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:21:28+00:00 2026-05-28T07:21:28+00:00

Good day, I am having an issue trying to get the Text on a

  • 0

Good day, I am having an issue trying to get the Text on a label to say ‘connecting …’ before the connection attempt starts and something else after it is connected. When the code below runs, the settext only displays once everything is complete. How can I get the first settext to display before the connection attempt?

private void buttonConnectActionPerformed(java.awt.event.ActionEvent evt) {
    try {
        String url = "jdbc:mysql://domain.com:3306/tablename";
        String user = "username";
        String password = "userpassword";

        jLabel.setText("Connecting ...");

        con = DriverManager.getConnection(url, user, password);

        jLabel.setText(con.getCatalog());

    } catch (SQLException ex) {
        Logger.getLogger(connection.class.getName()).log(Level.SEVERE, null, ex);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:21:29+00:00Added an answer on May 28, 2026 at 7:21 am

    The problem is that you are trying to connect to the database in your EventDispatcherThread which is basically the thread in charge of all the GUI items you have. The thread is taking it’s time to connect to the database and once it completes (ie. it connects to the database) it updates your GUI.

    You can use something like this to get it to work:

    private void buttonConnectActionPerformed(java.awt.event.ActionEvent evt) {
            jLabel.setText("Connecting ...");
    
            new Thread(new Runnable()
            {
                @Override
                public void run()
                {
                    try {
                             String url = "jdbc:mysql://domain.com:3306/tablename";
                             String user = "username";
                             String password = "userpassword";
    
    
    
                             con = DriverManager.getConnection(url, user, password);        
    
                         } catch (SQLException ex) {
                             Logger.getLogger(connection.class.getName()).log(Level.SEVERE, null, ex);
    }
                }
            }
            )).start()        
    }
    

    I am assuming that con is some global variable. In this case, for it to be accessible within the run() method, it needs to be declared as final.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hope you're having a good day. Another socket issue, another day :) I finally
Good Day. I'm having a problem with running a ajax call before a form
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good Day All we are trying to do is inside a trigger make sure
Good day everybody! Having the following code: template<typename T, typename OutStream = std::ostream> struct
Good day all, I am having some trouble with image permissions. I am loading
good day, i am having a bit of a problem here. i am using
Good day, I am having a little bit of a problem. I want to
Good Day, I have been trying various methods both found on here and in
good day! I am having a problem on showing the updated version of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.