无法获取到Oracle的JDBC连接



我正在尝试使用JDBC连接我的Spring Boot应用程序到我的Oracle数据库。

项目的总体设计是能够执行CRUD操作。

当我开始编译和运行我的项目时,没有出现任何问题。

当我尝试使用应用程序中的预定端口连接到浏览器中的本地主机时。属性文件,我从浏览器得到以下错误消息:

There was an unexpected error (type=Internal Server Error, status=500).
Failed to obtain JDBC Connection; nested exception is 
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
我在Eclipse控制台中收到的(最小化的)错误消息如下:

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:801) ~[ojdbc8-18.3.0.0.jar:18.3.0.0.0]
...
...
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:569) ~[ojdbc8-18.3.0.0.jar:18.3.0.0.0]
...
...
Caused by: java.net.UnknownHostException: locahost
at java.net.InetAddress.getAllByName0(Unknown Source) ~[na:1.8.0_151]
...
...
2021-08-14 10:09:01.177 ERROR 33096 --- [nio-8095-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; 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] with root cause
java.net.UnknownHostException: locahost
at java.net.InetAddress.getAllByName0(Unknown Source) ~[na:1.8.0_151]
...
...

我的TNSListener和OracleServiceXE都在运行

以及。ora文件

XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = LAPTOP-R01ERMVG)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = XE)
)
)
LISTENER_XE =
(ADDRESS = (PROTOCOL = TCP)(HOST = LAPTOP-R01ERMVG)(PORT = 1521))

ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)

侦听器。ora文件

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=salesdb.mycompany)
(SID_NAME=XE)         
(ORACLE_HOME=C:appbendgproduct18.0.0dbhomeXE)
#PRESPAWN CONFIG
(PRESPAWN_MAX=20)
(PRESPAWN_LIST=
(PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1))
)
)
)

我的hosts文件有一行声明:

127.0.0.1       localhost

对于我的项目构建:

  • Springboot 2.1.8版本
  • Apache Tomcat v7.0
  • ojdbc8
  • Oracle-SQL-Developer 18.3.0.0
  • JDK 8

应用程序。属性文件

spring.datasource.url=jdbc:oracle:thin:@locahost:1521:XE
spring.datasource.username=system
spring.datasource.password=password
logging.level.root=INFO
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
server.port=8095

pom.xml

文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.codejava</groupId>
<artifactId>central</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>

<!-- Dependencies -->

<dependencies> 
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>18.3.0.0</version>                         
</dependency>

</dependencies>

<build>
<plugins>
<plugin> 
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>               
</plugin>           
</plugins>      
</build>

</project>

Oracle数据库连接:

  • 连接名称:XE
  • 认证类型:Default
  • 用户名:系统
  • <
  • 密码:密码/gh>
  • 主机名:localhost
  • 端口:1521
  • 席德:xe

从阅读类似的问题和答案听起来好像有一个问题在我的tnsnames/listener文件,但我无法区分问题在于我的项目在摆弄了两天的最好的部分后。

更新应用程序。属性到下面并检查这可能会解决您的连接性

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XE

相关内容

  • 没有找到相关文章

最新更新