使用
我正在尝试使用JDBC驱动程序从Java应用程序连接到数据库。这失败了“ORA-01017:无效的用户名/密码;登录被拒绝”消息。
我计算机上安装的东西(我没有电源):
我不认为这些是干扰,因为从Eclipse项目使用的库中删除ojdbc6.jar会导致没有输出(没有错误,也没有select子句的输出),所以我很确定实际上正在使用瘦驱动程序。
我已经创建了一个小型测试应用程序来演示这个问题:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class OracleTester {
public static void main(String[] args) {
String database = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xx.xxx.xxx)(PORT=13301)))(CONNECT_DATA=(SERVICE_NAME=something)))";
String username = "myUser";
String password = "myPass";
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(database,username,password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select 'hello' from dual");
while(rs.next()){
System.out.println("output: " + rs.getString(0));
}
conn.close();
}
catch(Exception e){
System.out.println(e.getLocalizedMessage());
}
System.out.println("Done!");
}
}
输出:
ORA-01017: invalid username/password; logon denied
Done!
答案 0 :(得分:2)
友好的数据库管理员来救援,发现这实际上是一个Oracle错误:
Problem Description:
--------------------
When trying to connect by using the JDBC THIN 11g driver to a database 11g
using Enterprise User Security (EUS) connections throw invalid username/
When usign the JDBC OCI driver the connection can be made.
现在 - 抓住你的帽子:
Available Workarounds:
----------------------
Use OCI.
请注意,我使用的是11.2.0.4,而错误是
Tested Versions:
----------------
JDBC THIN Driver 11.1.0.6.0 and 11.1.0.7.0
显然,它已经存在了一段时间。我不确定我是否得到了这个 - 为什么如果它无法正确连接到数据库,它们会带出这个驱动程序的新版本?似乎这是每个人在使用瘦驱动程序时遇到的第一个问题?
然而,我们的本地数据库管理员英雄挖了这个:
Set the property oracle.jdbc.thinLogonCapability=o3 for the JDBC connection by passing the option oracle.jdbc.thinLogonCapability=o3 on the command line.
For example:
java -Doracle.jdbc.thinLogonCapability=o3 <Java Class>
There is no loss of security when following this workaround.
在Eclipse中,我已将此行添加到VM参数(运行 - &gt;运行配置 - &gt;参数 - &gt; VM参数 - &gt; add -Doracle.jdbc.thinLogonCapability = o3)和不料,我终于可以进入数据库了。
答案 1 :(得分:0)
另外需要注意:SQLDeveloper使用JDBC瘦驱动程序。因此,如果您可以与SQLDeveloper连接,那么您还应该能够从独立的JDBC程序进行连接。只需确保SQLDeveloper使用与您正在使用的jar文件相同的jdbc jar。如果要检查您正在使用的JDBC驱动程序的版本,请执行“java -jar ojdbc7.jar”,它将打印该版本。
答案 2 :(得分:0)
System.setProperty("oracle.net.wallet_location", [wallet location]);
System.setProperty("oracle.net.tns_admin", [Tns location]);
"url" = "jdbc:oracle:thin:/@tns_alias"
"driver_class" = "oracle.jdbc.driver.OracleDriver"