Skip to content

Commit

Permalink
Feat: Added a connection check in DatabaseManager
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 11, 2026
1 parent 7f022b0 commit 2a37af8
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ public DatabaseManager(){
this.connection = new DatabaseConnection();
}

/**
* Connection test for the Database.
* Does a simple SELECT SQL query and returns either true og and Exception if failed
*
* @return true if Sucsedd or SQLExepction if failed
*/
public boolean testConnection() {
try (Connection conn = connection.getMySqlConnection();
Statement stmt = conn.createStatement()) {

ResultSet rs = stmt.executeQuery("SELECT 1");

if (rs.next()) {
System.out.println("Database connection verified.");
return true;
}

} catch (SQLException e) {
System.out.println("Database connection failed.");
e.printStackTrace();
}

return false;
}

/**
* Creates the {@code charities} table if it does not already exist.
* <p>
Expand Down

0 comments on commit 2a37af8

Please sign in to comment.