我在使用 oracle 钱包作为密码存储将我的 java 应用程序连接到 oracle 数据库时遇到问题。
为了隔离问题,我制作了一个小型 Main 类,如下所示:
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
任何人都可以帮助我吗?谢谢阅读。河。