无法连接到oracle数据库.它说“无法从数据源确定jdbc url". [英] Unable to connect to oracle database.It says "Unable to determine jdbc url from datasource"
问题描述
我在项目中使用了spring boot,并且我有一些需要指定的oracle数据库属性.它们是:
I have used spring boot in my project and I have the few properties of my oracle database that needs to be specified.They are:
Schema Name=OWNER
Password=OWNER
Database Name=DCGCDB
它位于我的服务器中,因此要连接的IP为192.168.1.5,端口号为1521.
It is located in my server so the IP to connect is 192.168.1.5 and the Port Number is 1521.
因此,在我的application.properties
文件中,我已经进行了一些设置以连接数据库,这里是:
So in my application.properties
file i have made some settings to connect database and here it is:
# 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
但是在构建项目时,我会遇到类似以下错误:
But when building the project I am getting error like:
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文件
I have added the oracle jar file in pom.xml
<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文件.
And also executed the statement mvn install:install-file -Dfile=oracle-ojdbc6-11.2.0.3.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
to install the oracle jar file.
推荐答案
遵循 Oracle FAQ 页上,您定义JDBC URL的方式是错误的.首先需要对此进行纠正:
Following the Oracle FAQ page, the way you have defined your JDBC URL is wrong. That needs correction firstly, from this:
旧的JDBC URL :jdbc:oracle:thin:192.168.1.5:1521:DCGCDB
对此:
新的JDBC URL :jdbc:oracle:thin@//192.168.1.5:1521/YourOracleServiceName
考虑DCGCDB
是您的Oracle服务名称.
Considering DCGCDB
is your Oracle's Service name.
第二,用于Oracle的方言有所不同.我不知道为什么!
Secondly, there is a difference in the dialect that is being used for Oracle. I don't know why!!!
您可以将org.hibernate.dialect.Oracle10gDialect
用作方言,而不是org.hibernate.dialect.MySQL5InnoDBDialect
.
You could possibly use org.hibernate.dialect.Oracle10gDialect
for the dialect instead of org.hibernate.dialect.MySQL5InnoDBDialect
.
希望这会有所帮助!
这篇关于无法连接到oracle数据库.它说“无法从数据源确定jdbc url".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!