maven找到mysql 连接池_maven项目使用Druid连接池配置步骤和注意事项[mysql数据库]...

本文介绍使用Druid连接池时遇到的问题及解决方法,包括与MySQL的版本匹配、异常处理、SSL连接配置等关键信息。

注:这两天搭建项目时,使用Druid连接池入了不少坑;以此记录;

MySQL Server 5.7.21 + mysql-connector-java 5.1.38 + druid 1.0.8

一.配置步骤:

1.pom.xml 引入相关jar包:

2.spring.xml 数据源配置:

3.Druid监控配置这里没有写,数据库相关信息也可以写在config.properties资源文件里面;

二.注意事项:

1.MySQL Server 和 mysql-connector-java 要对应 ,如果是使用了 MySQL Server 8+和 mysql-connector-java8+ 版本;

&serverTimezone=时区标志" />

2. 报错:

java.sql.SQLException: Unknown system variable 'tx_isolation'

.com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

Caused by: java.lang.NullPointerException

at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3299)

原因是MySQL Server 和 mysql-connector-java 版本不一致,使Druid驱动加载不能连接数据库;改成相应版本就行;如MySQL Server 5.7.21 + mysql-connector-java 5.1.38 + druid 1.0.8

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,如:

jdbc:mysql://localhost:3306/manangement?useUnicode=true&characterEncoding=utf8&useSSL=false

(如果在配置中发现其他错误,可以补充。谢谢。)

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值