Donatello
Donatello

Reputation: 353

How to handle MySQL CommunactionException which occurs when database turns off when application is running

Spring Boot Application uses MySQL + C3p0 DataSource.
This DataSource I use to work with JDBC and JPA(provider Hibernate).

In every JDBC DAO layer method I have try/catch SQLException. And this catch block realy catch this Communication Exception but..

But when I try so send requests more and more I start to have this stacktrace.

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

Caused by: java.net.ConnectException: Connection refused: connect

+ many details ..

And finally I catch in SQLException catch block:

java.sql.SQLException: Connections could not be acquired from the underlying database!

Before this message application looked like It can't connect and It know It.
It gives responses with 500 status code very fast.

After this message application looks like It try to connect and can't understand that It can't. In this case It gives responses very slowly.

After switching on the database, application works without restart.

Upvotes: 0

Views: 83

Answers (1)

knkumar93
knkumar93

Reputation: 188

The big stack trace might be printed by the web server on which your application is running. May not be from your code. You need to read about your web server on how to avoid such stack trace printing.

Upvotes: 1

Related Questions