文件下载:
- JDBC JAR文件(版本18.3):
ojdbc8.jar
ons.jar
oraclepki.jar
osdt_cert.jar
osdt_core.jar
ucp.jar
注意:在此处下载JAR文件: JDBC JAR文件
步骤
-
将wallet文件解压放入项目:
eg.C:\IdeaProjects\projectName\src\main\resources\oracleWallet -
修改ojdbc.properties,注释第二行并放开后四行,替换后四行中的<password_from_console>,(应该是下载wallet时填写的密码,凭记忆补充的这段)
# Connection property while using Oracle wallets.
#oracle.net.wallet_location=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=${TNS_ADMIN})))
# FOLLOW THESE STEPS FOR USING JKS
# (1) Uncomment the following properties to use JKS.
# (2) Comment out the oracle.net.wallet_location property above
# (3) Set the correct password for both trustStorePassword and keyStorePassword.
# It's the password you specified when downloading the wallet from OCI Console or the Service Console.
javax.net.ssl.trustStore=${TNS_ADMIN}/truststore.jks
javax.net.ssl.trustStorePassword=<password_from_console>
javax.net.ssl.keyStore=${TNS_ADMIN}/keystore.jks
javax.net.ssl.keyStorePassword=<password_from_console>
- 将下载的所有jar文件放入项目并在pom中引用
eg.
<!--oracle--><dependency><groupId>cn.project</groupId><artifactId>ojdbc</artifactId><version>1.0.0-SNAPSHOT</version><scope>system</scope><systemPath>${pom.basedir}/src/main/resources/lib/ojdbc8.jar</systemPath></dependency>
- 配置properties
eg.
spring.datasource.jdbc-url=jdbc:oracle:thin:@jdbctest_medium?TNS_ADMIN=C:\IdeaProjects\projectName\src\main\resources\oracleWallet
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.username=username
spring.datasource.password=password
值得注意的是:TNS_ADMIN=地址 这个配置是连接到wallet目录的,该目录下面要有tnsnames.ora;有文章表示可以配置到环境变量中,这个没有尝试。
其中,jdbctest_medium这个参数可以在wallet中的tnsnames.ora查看;我重命名过,可能和你们看到的有所不同。并且这三种连接方式我并没有研究,有兴趣的自行查阅。
参考:
- Autonomous Transaction Processing (ATP), SpringBoot and JDBC
- Java Connectivity with Autonomous Database (ATP or ADW) using 19c and 18.3 JDBC