我在我的项目中使用了 spring boot,并且我的 oracle 数据库有一些需要指定的属性。它们是:
Schema Name=OWNER
Password=OWNER
Database Name=DCGCDB
它位于我的服务器中,因此要连接的 IP 是 192.168.1.5,端口号是 1521。
因此,在我的 application.properties
文件中,我进行了一些连接数据库的设置,如下:
# Oracle settings
spring.datasource.url=jdbc:oracle:thin:192.168.1.5:1521:DCGCDB
spring.datasource.username=OWNER
spring.datasource.password=OWNER
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
# logging
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.level.org.hibernate.SQL=debug
#logging.level.org.hibernate.type.descriptor.sql=trace
#logging.level.=debug
但是在构建项目时我收到如下错误:
o.s.b.a.orm.jpa.DatabaseLookup - Unable to determine jdbc url from
datasource org.springframework.jdbc.support.MetaDataAccessException:
Could not get Connection for extracting meta-data; nested exception is
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to
obtain JDBC Connection; nested exception is
java.sql.SQLRecoverableException: IO Error: The Network Adapter could
not establish the connection at
org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:328)
我已经在pom.xml中添加了oracle jar文件
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
并且还执行了语句mvn install:install-file -Dfile=oracle-ojdbc6-11.2.0.3.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
安装 oracle jar 文件。
最佳答案
遵循Oracle FAQ页面,您定义 JDBC URL 的方式是错误的。首先需要纠正的是:
旧 JDBC URL:jdbc:oracle:thin:192.168.1.5:1521:DCGCDB
对此:
新 JDBC URL:jdbc:oracle:thin@//192.168.1.5:1521/YourOracleServiceName
考虑 DCGCDB
是您的 Oracle 服务名称。
其次,Oracle 使用的方言存在差异。我不知道为什么!!!
您可以使用org.hibernate.dialect.Oracle10gDialect
作为方言,而不是org.hibernate.dialect.MySQL5InnoDBDialect
。
希望这有帮助!!!
关于java - 无法连接到oracle数据库。它说 "Unable to determine jdbc url from datasource",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53369343/