diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/database/DatabaseManager.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/database/DatabaseManager.java index 3e5357d..9e1fd3c 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/database/DatabaseManager.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/database/DatabaseManager.java @@ -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. *