2017-03-02 104 views
2

我正在面臨使用oracle錢包作爲密碼存儲將我的java應用程序連接到oracle數據庫的問題。JDBC 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))) 

,對於TNSNAMES

... 
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 

任何人都可以幫我嗎? 感謝您的閱讀。 r。

+0

看起來像錢包位置問題,因爲ORA-17168意味着 遇到了祕密存儲的問題。檢查錢包位置是否存在打開的錢包(cwallet.sso),並確保該錢包使用mkstore實用程序包含正確的憑證。檢查您是否指向正確的位置。 – Maverick

+0

路徑是正確的,並且cwallet.sso在那裏。此外,我測試他使用mkstore實用程序對密鑰庫進行爭論,並且存在XE條目 –

回答

-1

SQLNET.AUTHENTICATION_SERVICES =(NTS)

不應認爲是TNS代替TNS ???