Bare tjek om Class#forName()
på JDBC-driveren kaster ikke ClassNotFoundException
.
try {
Class.forName(driverClassName);
// Success.
}
catch (ClassNotFoundException e) {
// Fail.
}
Bare tjek om DriverManager#getConnection()
eller DataSource#getConnection()
kaster ikke SQLException
.
try (Connection connection = DriverManager.getConnection(url, username, password)) {
// Success.
}
catch (SQLException e) {
// Fail.
}