JDBC Oracle钱包连接

p5cysglq  于 2022-10-04  发布在  Oracle
关注(0)|答案(3)|浏览(935)

我在使用Oracle Wallet作为密码存储将我的Java应用程序连接到Oracle数据库时遇到了问题。

为了隔离问题,我创建了一个小的主类,如下所示:

public static void main(String[] args) {
Connection conn;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
System.setProperty("oracle.net.tns_admin", "c:\tns");
OracleDataSource ds = new OracleDataSource();
Properties props = new Properties();
System.setProperty("oracle.net.wallet_location", "c:/wallet2");

ds.setConnectionProperties(props);
ds.setURL("jdbc:oracle:thin:/@XE2");
Provider p;
p = new OraclePKIProvider();
Security.insertProviderAt(p, 3);
conn = ds.getConnection();

} catch (SQLException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);

} catch (ClassNotFoundException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
}

在目录c:\tns中,我有以下文件:

sqlnet.ora
tnsnames.ora

这是sqlnet.ora的列表

SQLNET.AUTHENTICATION_SERVICES = (NTS)
names.directory_path = TNSNAMES
SQLNET.WALLET_OVERRIDE = TRUE

# WALLET_LOCATION = (SOURCE=(METHOD=FILE)METHOD_DATA=(DIRECTORY=c:wallet))

WALLET_LOCATION = (SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=c:/wallet)))

对于tnsname来说

...
XE2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

在c:\wallet2中有以下文件:

cwallet.sso
ewallet.p12

该文件以前是用orapki生成的,我的条目名为xe2,具有正确的凭据。当我运行代码时,我得到以下异常

Could not open wallet. java.io.IOException: Could not open wallet. Check password

启用Oracle跟踪后,我可以看到以下几行:

mar 02, 2017 3:57:00 PM oracle.jdbc.driver.DatabaseError findMessage
TRACE_30:          Enter: "ORA-17168", java.io.IOException: Could not open wallet. java.io.IOException: Could not open wallet. Check password
mar 02, 2017 3:57:00 PM oracle.jdbc.driver.Message11 msg
TRACE_30: 72B6CBCC Enter: "ORA-17168", java.io.IOException: Could not open wallet. java.io.IOException: Could not open wallet. Check password
mar 02, 2017 3:57:00 PM oracle.jdbc.driver.Message11 msg
TRACE_30: 72B6CBCC Exit [0.066509ms]

mar 02, 2017 3:57:00 PM oracle.jdbc.driver.PhysicalConnection getSecretStoreCredentials
GRAVE:          Throwing SQLException: 168java.io.IOException: Could not open wallet. java.io.IOException: Could not open wallet. Check password

有人能帮我吗?谢谢你的阅读。河

rjee0c15

rjee0c151#

这是一个非常古老的主题。-tns_admin应指向钱包位置(C:\wallet2)-在tnsnames.ora wallet_Location为C:\wallet2,而不是c:/walet

erhoui1w

erhoui1w2#

我认为您的ewallet.p12文件受密码保护。

您是否需要使用密码设置oracle.net.wallet_password属性:

System.setProperty("oracle.net.wallet_password", "PASSWORD");

如果指定了密码,则the driver looks为p12文件,否则使用SSO文件。

6jygbczu

6jygbczu3#

SQLNET.AUTHENTICATION_SERVICES=(NTS)

这应该是TNS而不是NTS。

相关问题