I got it working by adding a try block on the
conn = DriverManager.getConnection(url, username, password);
on the first method. it looks like this:
try {
conn = DriverManager.getConnection(url, username, password);
reachable = TestDB(conn);
} catch (Exception e) {
reachable = false;
}
It is because the error is not with the second method. the error is the declaration of the connection.