As Far as I understood, You are trying to show a message that the Database is unavailable,
To do that, You can use Excepion Handling Techniques offered by the Java Language,
The General Format of handling an exception is
try
{
}
catch(Exception e)
{
}
The catch statement can be different exception types and can be given different exception handling codes for different exceptions.
a quick but incomplete solution could be,
try
{
}
catch(Exception e)
{
System.out.println("ERROR : Could not connect to database.");
}
If you also need the stack trace for debugging purposes you can also use
e.printStackTrace();