我正在使用带有eclipse氧气的Oracle 11g,我正在尝试设置Jdbc连接, 我正在使用连接语句
Connection con = DriverManager.getConnection("jdbc:oracle:thin:testuser/testuser@localhost");
我确信用户名和密码是正确的,但我仍然在
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:389)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:382)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:573)
at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:431)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:366)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:752)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:366)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JDBC.main(JDBC.java:12)
有人可以帮忙吗?
答案 0 :(得分:0)
也许您可以尝试使用从JAVASE教程中获取的此代码段:
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", this.userName);
connectionProps.put("password", this.password);
if (this.dbms.equals("mysql")) {
conn = DriverManager.getConnection(
"jdbc:" + this.dbms + "://" +
this.serverName +
":" + this.portNumber + "/",
connectionProps);
} else if (this.dbms.equals("derby")) {
conn = DriverManager.getConnection(
"jdbc:" + this.dbms + ":" +
this.dbName +
";create=true",
connectionProps);
}
System.out.println("Connected to database");
return conn;
编辑: 或者您可以尝试指定用户和密码,如下所示:
Connection conn = DriverManager.getConnection("
jdbc:oracle:thin:@localhost:1521:example", "example","password123");
答案 1 :(得分:0)
您在数据库中有一个默认的区分大小写的用户名和密码。必须在区分大小写时正确键入用户名和密码,或更改Oracle sec_case_sensitive_logon=false
身份验证的参数。
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> show parameter sec_case
NAME TYPE VALUE
------------------------------------ ----------- -----------------------------
sec_case_sensitive_logon boolean TRUE
SQL> alter system set sec_case_sensitive_logon=false scope=both;
System altered.
SQL> show parameter sec_case
NAME TYPE VALUE
------------------------------------ ----------- -----------------------------
sec_case_sensitive_logon boolean FALSE
SQL>