• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Test Connection in a Java Program

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic