如何防止使用JDBC和Java锁定帐户?

时间:2015-04-06 15:32:54

标签: java sql-server oracle jdbc exception-handling

我目前有一个连接到SQL Server数据库和Oracle数据库的Java应用程序。我遇到的问题是我的代码太迟引发了无效密码的异常。许多生产数据库都有一个条件,在经过这么多无效尝试后锁定帐户。在我的测试中,似乎它一直在尝试直到它自己锁定,然后它会抛出异常并显示错误消息。任何帮助表示赞赏。代码如下。

 try{
    if (ini.get("Connection", "SQL Server", boolean.class)) {
        dbURL = "jdbc:sqlserver://" + ini.get("Connection", "Hostname", String.class) + ":" + ini.get("Connection", "Port", String.class) + ";databaseName=" + ini.get("Connection", "Database", String.class);
        classType = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        Class.forName(classType);
        con = DriverManager.getConnection(dbURL, userName, password);
    } else if (ini.get("Connection", "Oracle", boolean.class)) {
        classType = "oracle.jdbc.driver.OracleDriver";
        dbURL = "jdbc:oracle:thin:@" + ini.get("Connection", "Hostname", String.class) + ":" + ini.get("Connection", "Port", String.class) + "/" + ini.get("Connection", "Instance", String.class);
        Class.forName(classType);
        con = DriverManager.getConnection(dbURL, userName, password);
    } else if (ini.get("Connection", "ODBC", boolean.class)){
        classType = "sun.jdbc.odbc.JdbcOdbcDriver";
        dbURL = "jdbc:odbc:scoreboard";
        Class.forName(classType);
        con = DriverManager.getConnection(dbURL, "", "");
    } else {
        classType = "net.ucanaccess.jdbc.UcanaccessDriver";
        Class.forName(classType);
        String Path = ini.get("Connection", "Access Path", String.class);;
        con=DriverManager.getConnection("jdbc:ucanaccess://" + Path);
    }
}
catch(Exception e){
    JOptionPane.showMessageDialog(null,
    "<html><body><p style='width: 200px;'> "+"Error Defining Database Connection Method: " + e.getMessage()+"</p></body></html>", "Error", JOptionPane.ERROR_MESSAGE);
    ini.put("Connection", "Success", false);
}
finally{
    try { if(con!=null){
            con.close();
        } 
    } catch (Exception e) { /* ignored*/ }
}

0 个答案:

没有答案