Kontrollera bara om Class#forName()
på JDBC-drivrutinen kastar inte ClassNotFoundException
.
try {
Class.forName(driverClassName);
// Success.
}
catch (ClassNotFoundException e) {
// Fail.
}
Kontrollera bara om DriverManager#getConnection()
eller DataSource#getConnection()
kastar inte SQLException
.
try (Connection connection = DriverManager.getConnection(url, username, password)) {
// Success.
}
catch (SQLException e) {
// Fail.
}