我想与oracle数据库连接。我已经创建了一个小项目,该连接工作正常。
public void makeCon() {
String url = "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCPS) (HOST =example.com) (PORT = 8080))) (CONNECT_DATA = (SERVER = DEDICATED)(SID = somesid)))";
Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "pass");
props.setProperty("javax.net.ssl.trustStore", "C:\\Users\\user1\\Desktop\\src\\main\\resources\\local.keystore");
props.setProperty("javax.net.ssl.trustStoreType", "JKS");
props.setProperty("javax.net.ssl.trustStorePassword", "secretpassword");
try {
Connection conn = DriverManager.getConnection(url, props);
} catch (SQLException e) {
e.printStackTrace();
}
}
此连接工作正常,我能够进行一些查询。现在,我想连接我的主要项目。我已经建立了基于应用程序属性的连接,并且一切正常,但是现在当我想更改将与SSO oracle连接的数据库时,那是行不通的。
@Bean(name = "sql")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource getDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "sqlDataNamed")
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource pricingDataSource) {
JdbcTemplate template = new JdbcTemplate(getDataSource());
template.setFetchSize(500);
return new NamedParameterJdbcTemplate(template);
}
我试图以某种方式将此密钥库添加到JdbcTemplate或数据源中,但是我做不到。该文档没有显示如何放置属性。 System.setProperties不起作用,之后出现错误:
Root exception is javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
感谢您的咨询