欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql8.x 新版本jdbc连接方式

程序员文章站 2022-04-15 16:16:51
注意:新版mysql驱动的url必须设置时区,即serverTimezone=UTC,否则会报如下错误: ......
  1. 旧版本,mysql connector/j 5.x 版本的连接方式:
    url = jdbc:mysql://localhost:3306/thrcloud_db01?useunicode=true&characterencoding=utf8
    driver-class-name = com.mysql.jdbc.driver
  2. 新版本,mysql connector/j 6.x之后 的连接方式:
    url = jdbc:mysql://localhost:3306/thrcloud_db01?servertimezone=utc&characterencoding=utf8&useunicode=true&usessl=false
    driver-class-name = com.mysql.cj.jdbc.driver

  注意:新版mysql驱动的url必须设置时区,即servertimezone=utc,否则会报如下错误:

mysql8.x 新版本jdbc连接方式

 

java.sql.sqlexception: 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 com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:129) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:97) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:89) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:63) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.exceptions.sqlerror.createsqlexception(sqlerror.java:73) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.exceptions.sqlexceptionsmapping.translateexception(sqlexceptionsmapping.java:76) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.connectionimpl.createnewio(connectionimpl.java:835) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.connectionimpl.<init>(connectionimpl.java:455) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.connectionimpl.getinstance(connectionimpl.java:240) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.mysql.cj.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:199) ~[mysql-connector-java-8.0.14.jar:8.0.14]
    at com.alibaba.druid.pool.druidabstractdatasource.createphysicalconnection(druidabstractdatasource.java:1464) ~[druid-1.0.31.jar:1.0.31]
    at com.alibaba.druid.pool.druidabstractdatasource.createphysicalconnection(druidabstractdatasource.java:1529) ~[druid-1.0.31.jar:1.0.31]
    at com.alibaba.druid.pool.druiddatasource$createconnectionthread.run(druiddatasource.java:2109) ~[druid-1.0.31.jar:1.0.31]
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.generatedconstructoraccessor29.newinstance(unknown source) ~[na:na]