Detect that server db is down

Hi,

I’d like detect that server db is down in application (vaadin + sqlcontainer). When error is exist, I’d like display own error information for user. I tried use this solution:

In tomcat web.xml I put:

<error-page>
 <error-code>500</error-code>
 <location>/error.html</location>
<error-page>
<error-page>
 <error-code>501</error-code>
 <location>/error.html</location>
<error-page>
<error-page>
 <error-code>404</error-code>
 <location>/error.html</location>
<error-page>

In main WebContent I put file error.html

And for tests I turn off server db (sql-server express) and redeployed webapp. When I starts webapp I’ve got error:

HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException

How can I do it?

Best regards,
Paul

Check your error logs (if you start the server from Eclipse, check Eclipse’s console). You got a NullPointerException, which doesn’t directly indicate a database problem, but some else programming error.

In any case, the best way to handle database connection errors is to just catch the appropriate exception (for example SQLException), and display the error messages via Vaadin with plain Labels, or whatever.