• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Test Connection in a Java Program

 
Erick Travis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, guys!

I was wondering how could I get some help with a Java problem I got and I thought "Hey I could ask the amazing guys at JavaRanch ".

So here I am I got a meeting scheduler that saves and extracts data from a DB and I wanted to do a status bar (just a jLabel) at the bottom of my interface
(to tell the user if the program can't establish a connection to the DB, saved meetings, saved changes, etc.).

I was using a TimerTask with a getConnection writing a "Connection Ready" in my status bar but I don't know if it's the best way to do it
and I was wondering if there is some kind of TestConnection method or something like that so I don't have to do the connection over and over again every time I need it.

Thanks in advance for everything and I appreciate any kind of answer.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you mean "interface", did you mean GUI?

A status bar can indeed be done using a JLabel.

To check whether the connection is available or not you can use Connection#isValid

Does your app use connection pool? If so the swing's Timer (taking in a delay and ActionListener) can be used to check this connectivity.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic