在若依框架中增加连接Oracle视图报错
工具测试连接
通过使用plsql连接数据库测试,连接成功
1. 相关配置内容
连接配置
url: jdbc:oracle:thin:@192.168.0.210:1521:HIS
username: portal_his
password: XXXXXX
driver-class-name: oracle.jdbc.driver.OracleDriver
依赖版本
xml
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
错误1
bash
12:57:22.428 [Druid-ConnectionPool-Create-1721235373] ERROR c.a.d.p.DruidDataSource - [run,2840] - create connection SQLException, url: jdbc:oracle:thin:@192.168.0.220:1521:HIS, errorCode 12505, state 66000
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1657)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1723)
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2838)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
修改连接:
url: jdbc:oracle:thin:@192.168.0.210:1521/HIS
错误2
bash
12:59:04.390 [Druid-ConnectionPool-Create-1473057156] ERROR c.a.d.p.DruidDataSource - [run,2840] - create connection SQLException, url: jdbc:oracle:thin:@192.168.0.220:1521/HIS, errorCode 12514, state 66000
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1657)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1723)
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2838)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
解决
- 通过plsql查看oracle版本
shell
SELECT * FROM V$VERSION;
1 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
2 PL/SQL Release 12.2.0.1.0 - Production 0
3 CORE 12.2.0.1.0 Production 0
4 TNS for Linux: Version 12.2.0.1.0 - Production 0
5 NLSRTL Version 12.2.0.1.0 - Production 0
- 修改依赖包版本
xml
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
- 查看实例名
bash
select INSTANCE_NAME from v$instance;
1 orcl
- 修改数据库连接配置
go
url: jdbc:oracle:thin:@192.168.0.210:1521:orcl
或
url: jdbc:oracle:thin:@192.168.0.210:1521/orcl
- 再次运行连接成功
bash
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7c4d52d9]
13:09:38.701 [RuoyiScheduler_Worker-1] INFO c.c.c.c.d.DynamicDataSourceContextHolder - [setDataSourceType,26] - 切换到HIS数据源
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@a703718] was not registered for synchronization because synchronization is not active
13:09:39.444 [RuoyiScheduler_Worker-1] INFO c.a.d.p.DruidDataSource - [init,998] - {dataSource-2} inited
JDBC Connection [oracle.jdbc.driver.T4CConnection@3bddc104] will not be managed by Spring
==> Preparing: select SHBH,HISLSH,HISDDH,YHKH,XTCKH,ZFSJ,YWLX,JYLX,ZFFS,ZFJE,YGDM,YGXM, JYQD,HZKH,BRID,BRXM,SJHM from V_LD_DZPT WHERE ZFSJ >= to_date(?, 'yyyy-mm-dd') AND ZFSJ <= to_date(?, 'yyyy-mm-dd') + 1
==> Parameters: 2025-02-25(String), 2025-02-25(String)
<== Columns: SHBH, HISLSH, HISDDH, YHKH, XTCKH, ZFSJ, YWLX, JYLX, ZFFS, ZFJE, YGDM, YGXM, JYQD, HZKH, BRID, BRXM, SJHM
- 说明
go
url: jdbc:oracle:thin:@192.168.0.210:1521:orcl
或
url: jdbc:oracle:thin:@192.168.0.210:1521/orcl
二者区别:
:和/的区别主要在于URL格式的不同,前者使用SID方式,后者使用ServiceName方式
1. 使用SID的方式:URL格式为 jdbc:oracle:thin:@host:port:SID,例如 jdbc:oracle:thin:@localhost:1521:orcl。这种方式需要指定主机名、端口和SID
2. 使用ServiceName的方式:URL格式为 jdbc:oracle:thin:@//host:port/ServiceName,例如 jdbc:oracle:thin:@//localhost:1521/orcl。这种方式需要指定主机名、端口和ServiceName