这里是我的代码:DriverManager.getConnection();如何确定用户名/密码是否错误或驱动程序无法连接到数据库?
public static Connection connectToDataBase() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (final Exception e) {
throw new RuntimeException("Driver failure");
}
connectionProperties = new Properties();
connectionProperties.put("user", user);
connectionProperties.put("password", passwor);
datenbankverbindung = DriverManager.getConnection(link, connectionProperties);
return connection;
}
我连接到数据库,工作正常。但我想知道登录数据是否错误或连接是否有问题。
哦,你为什么不检查抛出的异常呢? –
我这样做,但我不知道如果f.e.错误消息是什么。 DriverManager无法连接到服务器。 – jv123