如何使用JDBC连接MySQL8.x-创新互联
这篇文章给大家分享的是有关如何使用JDBC连接MySQL 8.x的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
创新互联是一家以网络技术公司,为中小企业提供网站维护、成都网站制作、网站建设、网站备案、服务器租用、域名注册、软件开发、小程序定制开发等企业互联网相关业务,是一家有着丰富的互联网运营推广经验的科技公司,有着多年的网站建站经验,致力于帮助中小企业在互联网让打出自已的品牌和口碑,让企业在互联网上打开一个面向全国乃至全球的业务窗口:建站电话联系:18980820575MySQL 8.x 新版本JDBC连接方式,旧版本,MySQL Connector/J 5.x 版本的连接方式,MySQL 8.x新版本,MySQL Connector/J 6.x之后 的连接方式,新版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 8.x新版本,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,否则会报如下错误:
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.(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]
感谢各位的阅读!关于“如何使用JDBC连接MySQL 8.x”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
文章题目:如何使用JDBC连接MySQL8.x-创新互联
本文URL:http://pwwzsj.com/article/ehjhp.html