Skip to content

Commit

Permalink
- Added a better error message when a database error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
mimic2300 committed May 27, 2018
1 parent 4f13c07 commit e55ee87
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.slf4j.LoggerFactory;

import java.lang.reflect.Parameter;
import java.sql.SQLException;
import java.util.*;

/**
Expand Down Expand Up @@ -66,7 +67,14 @@ public static void main(String[] args) {
try {
HibernateManager.initialize(config);
} catch (DatabaseConnectionException e) {
LOG.error("Database connection failed. Verify that the database server is running and that it is " + "configured correctly. The database will not be used");
if (e.getCause() != null && e.getCause() instanceof SQLException) {
var eSql = (SQLException) e.getCause();
LOG.error("A database error has occurred: SQL state {}, message: {}", eSql.getSQLState(), eSql
.getMessage());
} else {
LOG.error("An unexpected error occurred when connecting to the database. The database will not be used. Message: {}", e
.getMessage());
}
}
}

Expand Down

0 comments on commit e55ee87

Please sign in to comment.