SpringBoot中连接oracle出现告警信息

本文涉及的产品
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 前几日领导说需要连接友商的Oracle,然后读取友商的数据展示到页面来。工作还是需要做的嘛,虽然比较简单些,但是工作量还是有的(此处划水摸鱼了呢?)。为了演示连接成功和可以读取数据,我在本地搭建了一个Oracle,然后作为测试来模拟读取,后续只需要替换下连接器的连接即可。然后,在启动SpringBoot项目时,有一个很显眼的WARN红色字体在控制台打印出来了。


问题出现的背景和原因

前几日领导说需要连接友商的Oracle,然后读取友商的数据展示到页面来。工作还是需要做的嘛,虽然比较简单些,但是工作量还是有的(此处划水摸鱼了呢?)。为了演示连接成功和可以读取数据,我在本地搭建了一个Oracle,然后作为测试来模拟读取,后续只需要替换下连接器的连接即可。然后,在启动SpringBoot项目时,有一个很显眼的WARN红色字体在控制台打印出来了。

WARN com.alibaba.druid.pool.DruidAbstractDataSource - oracle.jdbc.driver.OracleDriver is deprecated.Having use oracle.jdbc.OracleDriver


当前我Oracle服务器的数据库版本为:11.2g ,此处画上一个重点,后续要考。


根据问题着手处理

虽然这个不影响项目的运行,但是出于看着不舒服的情况,我还是决定看看这个告警出现的问题。仔细一看,这个问题还是比较简单的。我找百度翻译给翻译下吧。

看出来了吧,是不是已经知道什么问题了?大白话就是在使用驱动连接器的类过期了,不在使用oracle.jdbc.driver.OracleDriver 这个驱动器类了,而是改为了oracle.jdbc.OracleDriver。相比以前好像是简洁了一个单词,少了一个也是一种进步,一种优化。看来我是很久都不用了。


思考的路永远欢迎你踏上去

为了增加我猜测的准确性,我决定还是百度下吧,下面看下官方提供的解释,我认为这个应该是比较准确了。

官方解释:

Package oracle.jdbc


Beginning in Oracle9i, the Oracle extensions to JDBC are captured in the packageoracle.jdbc. This package contains classes and interfaces that specify the Oracle extensions in a manner similar to the way the classes and interfaces injava.sqlspecify the public JDBC API.


Your code should use the packageoracle.jdbcinstead of the packageoracle.jdbc.driverused in earlier versions of Oracle. Use of the packageoracle.jdbc.driveris now deprecated, but will continue to be supported for backwards compatibility.


All that is required to covert your code is to replace "oracle.jdbc.driver" with "oracle.jdbc" in the source and recompile. This cannot be done piece-wise. You must convert all classes and interfaces that are referenced by an application. Conversion is not required, but is highly recommended. Future releases of Oracle may have features that are incompatible with use of the packageoracle.jdbc.driver.


The purpose of this change is to enable the Oracle JDBC drivers to have multiple implementations. In all releases up to and including Oracle9i, all of the Oracle JDBC drivers have used the same top level implementation classes, the classes in the packageoracle.jdbc.driver. By converting your code to useoracle.jdbc, you will be able to take advantage of future enhancements that use different implementation classes. There are no such enhancements in Oracle9i, but there are plans for such enhancements in the future.


Additionally, these interfaces permit the use of some code patterns that are difficult to use when your code uses the packageoracle.jdbc.driver. For example, you can more easily develop wrapper classes for the Oracle JDBC classes. If you wished to wrap theOracleStatementclass in order to log all SQL statements, you could easily do so by creating a class that wrapsOracleStatement. That class would implement the interfaceoracle.jdbc.OracleStatementand hold anoracle.jdbc.OracleStatementas an instance variable. This wrapping pattern is much more difficult when your code uses the packageoracle.jdbc.driveras you cannot extend the classoracle.jdbc.driver.OracleStatement.


Once again, your code should use the new packageoracle.jdbcinstead of the packageoracle.jdbc.driver. Conversion is not required asoracle.jdbc.driverwill continue to be supported for backwards compatibility. Conversion is highly recommended as there may in later releases be features that are not supported if your code usesoracle.jdbc.driver.

Since:

9i

See Also:

java.sql

这篇文章的地址来源于:https://docs.oracle.com/en/database/oracle/oracle-database/21/jajdb/oracle/jdbc/package-summary.html 有兴趣的小伙伴可以阅读,可以提升下下英文阅读能力。


综合上述可见,从oracle9i开始,使用oracle.jdbc.OracleDriver代替oracle.jdbc.driver.OracleDriver。如果继续使用oracle.jdbc.driver.OracleDriver,在后续可能出现不支持某些功能。oracle.jdbc.OracleDriver 继承oracle.jdbc.driver.OracleDriver,是为了与老版本兼容,这也就可以说明我这里出现问题的原因了。


解决办法多数情况是一种取舍

先看下我原来的在YML中配置multi-card-oracle的驱动信息

省略……
      datasource:        master:          url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/jmd-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
          username: xxxxxx
          password: xxxxxxxxxx
          driver-class-name: com.mysql.cj.jdbc.Driver
# 多数据源配置        multi-card-oracle:          url: jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:xxxxxxx
          username: xxxxxx
          password: xxxxxxxxxx
          driver-class-name: oracle.jdbc.driver.OracleDriver
省略……

oracle.jdbc.driver.OracleDriver替换为oracle.jdbc.OracleDriver就可以了消除上面的告警信息了。


关于Oracle的工具连接使用的驱动器类

说到这里,其实还有一种方式可以避免这种问题的出现。我们在使用工具连接数据库服务器的时候,填写完成必要信息后,选择数据库类型,此时,工具会根据你的数据库服务器的版本来选择最优的驱动连接器,此时的驱动器连接器的类名称便是你需要的连接驱动器类。


关于MySQL的驱动器类

想到这里,其实,这个同我们在使用MySQL时是一样的道理。例如,我们在使用MySQL时,使用的驱动器为com.mysql.cj.jdbc.Driver,则代表我们连接的数据库服务器的版本为8.0+,如果是com.mysql.jdbc.Driver则是8.0以下的MySQL版本。

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3天前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的电影信息推荐APP的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的电影信息推荐APP的详细设计和实现(源码+lw+部署文档+讲解等)
|
4天前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的ITS 信息平台的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的ITS 信息平台的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的ITS 信息平台的详细设计和实现(源码+lw+部署文档+讲解等)
|
6天前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的新能源汽车信息咨询服务附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的新能源汽车信息咨询服务附带文章源码部署视频讲解等
10 1
|
7天前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的高校毕业生就业信息系统小程序附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的高校毕业生就业信息系统小程序附带文章源码部署视频讲解等
11 2
|
7天前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的电影信息推荐APP附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的电影信息推荐APP附带文章源码部署视频讲解等
16 1
|
3天前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的分类信息服务平台的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的分类信息服务平台的详细设计和实现(源码+lw+部署文档+讲解等)
|
7天前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的分类信息服务平台附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的分类信息服务平台附带文章源码部署视频讲解等
8 0
|
7天前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的农业信息智能化种植系统附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的农业信息智能化种植系统附带文章源码部署视频讲解等
8 0
|
9天前
|
JavaScript Java 测试技术
基于SpringBoot+Vue的黄河森林公园景区票务管理信息系统的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue的黄河森林公园景区票务管理信息系统的详细设计和实现(源码+lw+部署文档+讲解等)
9 0
|
10天前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的机电公司管理信息系统附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的机电公司管理信息系统附带文章源码部署视频讲解等
14 0

推荐镜像

更多