驱动版本问题:connect error, url mysql.db.url:jdbc:mysql://IP地址:3306/数据库名

MySQL升级版本 5.7.43

必须升级驱动版本 8.0 以上版本

启动项目报错

使用Druid数据库连接池获取Mysql常见的错误--不兼容问题

后来百度搜索发现原来是Mysql版本和mysql-connector-java版本不一致造成的。

查询Mysql版本号:

SELECT version();

然后去官网找对应版本mysql-connector-java

下载解压后就能找到对应的mysql-connector-java-8.0.11.jar将这个jar包拖金IDEA,右键点击它,然后选择add as a library

再次运行测试文件,发现还是抛出了NullPointerException异常:

Establishing SSL connection without server's identity verification is

not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+

requirements SSL connection must be established by default if explicit

option isn't set. For compliance with existing applications not using

SSL the verifyServerCertificate property is set to 'false'. You need

either to explicitly disable SSL by setting useSSL=false, or set

useSSL=true and provide truststore for server certificate

verification.

以上报错信息来看、大概意思就是不建议在没有服务器身份验证的情况下建立SSL连接

此时我们需要在url后面加两个个参数useSSL=false,用?与数据库的url隔开,两个参数之间用&隔开

如:jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC

(jdbc.properties配置文件中的url也改成上面的)

之后我们再次运行mysql.java文件,发现已经可以正常连接到数据库。

相关推荐
AIgorithmGEEK3 小时前
MySQL 索引全解(下):建、查、删实战与知识速查表
数据库·mysql·b+树·索引
Lost_the_wind3 小时前
MySQL学习笔记四
mysql
唠点键盘之外的5 小时前
26 向量数据库实战:从 0 搭一条能用的检索链路(pgvector + Spring AI)
数据库·人工智能·spring
云和恩墨5 小时前
数据库监控简史:监控不止于告警——从图表大爆发到健康管理闭环
数据库
ly76896 小时前
MongoDB 事务开销实测:快照隔离下的写冲突、重试与分片事务边界
数据库·mongodb·事务·分片集群·快照隔离·写冲突
豆角焖肉6 小时前
Spring AOP 自定义注解实现系统操作日志
数据库·自定义注解·springaop·操作日志·aop 切面
金伟API10247 小时前
不会写复杂SQL怎么办?
数据库·sql
执笔为剑7 小时前
2.1.2-1、V8R3迁移到V8R6-Oracle兼容特性
数据库
geovindu8 小时前
sql:Search-Optimized SQL Queries using mysql 9.0
android·数据库·sql·mysql·数据库开发·数据库架构
for_ever_love__8 小时前
MySQL SELECT 与 WHERE 优化实战:可搜索条件、联合索引与执行计划
数据库·mysql·oracle·select·where·条件优化·查询优化技巧