我正在尝试在我的春季应用中配置oracle钱包。以下是错误:
我把所有配置文件(cwallet.sso,ewallet.p12)和&罐子()&设置tnsnames.ora 下面是代码。
private DriverManagerDataSource getDriverManagerDataSource(final String driver,
final String url,
final String username,
final String password) {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
Properties props = new Properties();
props.put("oracle.net.wallet_location", pathToWallet);
dataSource.setConnectionProperties(props);
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
//dataSource.setUsername(username);
//dataSource.setPassword(password);
return dataSource;
}
答案 0 :(得分:-1)
Malik,
示例程序没有完整的信息。
我认为在您的程序中,如果您替换下面的代码
属性props = new Properties(); props.put(“ oracle.net.wallet_location”,pathToWallet);
使用
System.setProperty(“ oracle.net.tns_admin”,“ tnsnames.ora_file_location ”); System.setProperty(“ oracle.net.wallet_location”,“ Oracle_Wallet_Location ”);
它应该可以解决您的问题。
我已按照以下步骤设置了我的Oracle钱包。
cd%ORACLE_HOME%\ BIN
mkstore -wrl D:\ oraclewallet \ wallet -create(提供钱包密码)
mkstore -wrl D:\ oraclewallet \ wallet -createCredential Tns_Entry_Name Schema_Name 密码
%ORACLE_HOME%\ NETWORK \ admin \ sqlnet.ora中的条目
WALLET_LOCATION =(SOURCE =(METHOD = FILE)(METHOD_DATA =(DIRECTORY = Oracle_Wallet_Location )))
SQLNET.WALLET_OVERRIDE = TRUE
在这里您应该能够使用sqlplus连接到数据库
sqlplus / @ Tns_Entry_Name
在运行Java程序时应设置以下Java运行时参数
-Doracle.net.tns_admin = %ORACLE_HOME%\ NETWORK \ ADMIN
-Doracle.net.wallet_location = Oracle_Wallet_Location
否则我们可以在运行时将其设置为
System.setProperty(“ oracle.net.tns_admin”,“%ORACLE_HOME%\ NETWORK \ ADMIN”);
System.setProperty(“ oracle.net.wallet_location”,“ Oracle_Wallet_Location”);
现在要获得数据库连接,您应该使用数据库URL作为
jdbc:oracle:thin:/ @ tns_entry_name
Sample Program Test Result Oracle Wallet
确保您在类路径中的jar下方
ojdbc6.jar
oraclepki.jar
osdt_cert.jar
osdt_core.jar
要测试的示例代码
package datasourcetest;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
public class DataSourceConnectionExample {
private static final String DRIVER_CLASS_NAME = "oracle.jdbc.driver.OracleDriver";
private static final String URL = "jdbc:oracle:thin:/@**tns_entry_name**";
public static void main(String[] args) throws SQLException {
System.setProperty("oracle.net.tns_admin", "**%ORACLE_HOME%\\NETWORK\\ADMIN**");
System.setProperty("oracle.net.wallet_location", "**Oracle_Wallet_Location**");
Connection conn = getDataSource().getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 'test' name FROM dual");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
}
public static DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(DRIVER_CLASS_NAME);
dataSource.setUrl(URL);
return dataSource;
}
}