在 java JDBC 连接错误 ORA-28000: the account got locked, but db account is not locked

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20988214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:45:55  来源:igfitidea点击:

In java JDBC connection error ORA-28000: the account got locked, but db account is not locked

javaoraclejdbc

提问by Teela

I could connect to Oracle XE, DB from console using the credentials (Username: HR, Password : *****). But I'm getting the error message

我可以使用凭据(用户名:HR,密码:*****)从控制台连接到 Oracle XE、DB。但我收到错误消息

ORA-28000: the account got locked

ORA-28000: 帐户被锁定

when I try to establish connection from java program using JDBC.

当我尝试使用 JDBC 从 java 程序建立连接时。

Code:

代码:

public static void main(String args[]) throws Exception{
          Class.forName("oracle.jdbc.driver.OracleDriver");
          String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
          Connection con = DriverManager.getConnection(url,"USER NAME","PASSWORD");
          Statement statement = con.createStatement();  
          ResultSet resultset = statement.executeQuery("select 'Connected' from dual");  

          while (resultset.next()) {
                 System.out.println(resultset.getString(1));
          }        
          statement.close();  
          con.close();  
   }

How to connect to DB from this java program?

如何从这个java程序连接到数据库?

回答by Teela

When connect using the credentials (Username : system, Password : ####) the account got connected without any issue from java program. However, when connected using the credentials (Username: HR, Password : **) got the error message ORA-28000: the account got locked. But was able to login using these HR credentials from oracle console. So, to get the connection from java program, did the following:

当使用凭据(用户名:系统,密码:####)连接时,帐户已连接,java 程序没有任何问题。然而,在使用的凭据连接(用户名:HR,密码:**)得到了错误消息ORA-28000:账户被锁。但是能够从 oracle 控制台使用这些 HR 凭据登录。因此,要从 java 程序获取连接,请执行以下操作:

public static void main(String args[]) throws SQLException, ClassNotFoundException{

          String query;

          // Connect to system Database first
          Class.forName("oracle.jdbc.driver.OracleDriver");
          String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
          Connection con = DriverManager.getConnection(url,"system","####");
          Statement statement = con.createStatement();  
          query = "alter user HR identified by HR account unlock";

          //Unlock the account
          ResultSet resultset = statement.executeQuery(query);

          //Connect to HR database
          con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","HR","****");
          statement = con.createStatement();  

          //Fetch all the tables in HR database
          query = "select 'Connected' from dual";
          resultset = statement.executeQuery(query);

          //Prints records fetched
          while (resultset.next()) {
                 System.out.println(resultset.getString(1));
          }        

          statement.close();  
          con.close();  

   }

The HR account got unlocked and now able to execute other queries without issues :)

HR 帐户已解锁,现在可以毫无问题地执行其他查询:)

回答by Dan_27

Just change the username to "System" instead of "HR". and that it! you will be able now to connect to your database.

只需将用户名更改为“System”而不是“HR”。和它!您现在可以连接到您的数据库。