1 遇到的错误com.mysql.cj.exceptions.InvalidConnectionAttributeException:

 四月 17, 2019 10:21:13 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 2udui8a2beimx6x8ptry|2f4d3709, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2udui8a2beimx6x8ptry|2f4d3709, idleConnectionTestPeriod -> 0, initialPoolSize -> 20, jdbcUrl -> jdbc:mysql://localhost:3306/test, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 30, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
四月 17, 2019 10:21:33 上午 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@26aa877c -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
四月 17, 2019 10:21:33 上午 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@26aa877c -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
....
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at sun.reflect.GeneratedConstructorAccessor32.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2234)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2258)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
... 11 more

2 解析

参考博客地址:https://blog.csdn.net/weixin_37577564/article/details/80329775

the server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. 

出现这个的原因是因为 mysql返回的时间总是有问题,比实际时间要早8小时。

在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8

3 解决方法

注意:首先检查mysql-connector-java-xxx.jar的版本,若过低,升成8.0.13

3.1 如果是在Java工具类里:

dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false");

3.2 如果是在配置文件里:

<property name="jdbcUrl">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=GMT%2B8&amp;useSSL=false</property>

以上,吼吼

c3p0连接池:com.mysql.cj.exceptions.InvalidConnectionAttributeException的更多相关文章

  1. Java连接MySql报错—— com.mysql.cj.exceptions.InvalidConnectionAttributeException

    详细报错 java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents mor ...

  2. com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. 问题解决方法

    一.问题 今天用mybatis连接数据库时出现了如下错误: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The serve ...

  3. java 连接数据库报错:Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '

    1.解决方法: 报错信息为: Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server ti ...

  4. com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'PDT' is.......

    SpringBoot连接数据库的时候报错 java.sql.SQLException: The server time zone value 'PDT' is unrecognized or repr ...

  5. Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä'

    java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more ...

  6. MyBatis——com.mysql.cj.exceptions.InvalidConnectionAttributeException

    报错信息 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.c ...

  7. 【JavaWeb】c3p0连接池与MySQL

    正文之前 在之前的文章讲到了传统的JDBC连接MySQL的方式,但是这样的方式在进行多个连接时,就显得效率低下,明显不如连接池的效率,所以我们这次来讲解一下JDBC连接池之一:c3p0 正文 1. 准 ...

  8. dbcp/c3p0连接池设置mysql会话变量

    我们有几个计算风控值的定时任务,几乎每隔5秒会更新所有账户的当前总资产并以此通知风控,每隔一小时就产生一两个G的binlog,几十台服务器折腾..数据库是公用的,代码是通过工具自动生成的,直接修改流程 ...

  9. com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼

    起初这样能短暂解决问题,后来发现每次机器重启了就还是有这样的错误,还是要执行SQL,很麻烦: show variables like '%time_zone%'; select now(); set ...

随机推荐

  1. Jenkins 远程部署

    参考:https://www.cnblogs.com/bookwed/p/4583033.html 准备环境: 本地开发,安装虚拟机,在虚拟机安装Linux服务器 步骤: 1.安装插件,登录到Jenk ...

  2. hadoop3.0.0部署

    配置前先查下JAVA_HOME的位置vim /etc/profile#set java environment JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1. ...

  3. Linux学习笔记(16)Linux前后台进程切换(fg/bg/jobs/ctrl+z)

    关键词:Linux前后台进程切换,linux进程切换 fg.bg.jobs.&.ctrl + z都是跟系统任务有关的,虽然现在基本上不怎么需要用到这些命令,但学会了也是很实用的一.& ...

  4. 【面试向】hihoCoder 1994 树与落叶

    题目链接 Implementation int n, q; scan(n,q); vi p(n + 1); vi nson(n + 1); up (i, 1, n) { scan(p[i]); nso ...

  5. Dango之模版系统

    1.模板渲染 可以传列表,字典,对象等 {{ 变量 }} {% 逻辑 %} -- 标签 urls.py path('login/', views.login), views.py def login( ...

  6. vscode中eslint插件的配置-prettier

    用vue-cli构建vue项目,会有个eslint代码检测的安装 可vscode自带代码格式化是prettier格式(右键有格式化文件或alt+shift+f) 这时候要在vscode上装一个esli ...

  7. .Net高并发解决思路

    转自: 本文如有不对之处,欢迎各位拍砖扶正.另源码在文章最下面,大家下载过后先还原一下nuget包,需要改一下redis的配置,rabbitmq的配置以及Ef的连接字符串.另外使用的是CodeFirs ...

  8. golang(6): 接口 & 反射

    接口详解 // 举例:sort包中的 Sort 函数,如下: func Sort(data Interface) Sort sorts data. It makes one call to data. ...

  9. luogu P3226 [HNOI2012]集合选数

    luogu 因为限制关系只和2和3有关,如果把数中2的因子和3的因子都除掉,那剩下的数不同的数是不会相互影响,所以每次考虑剩下的数一样的一类数,答案为每类数答案的乘积 如果选了一个数,那么2的因子多1 ...

  10. Reducing Snapshots to Points: A Visual Analytics Approach to Dynamic Network Exploration

    ---恢复内容开始--- 分析静态网络的方法:(1)节点链接图 (2)可视化邻接矩阵 and(3)hierarchical edge bundles. 分析网络演变的方法:(1)时间到时间的映射和(2 ...