首页 > 数据库技术 > 详细

JDBD连接MySQL中的驱动与时区问题

时间:2019-11-18 14:44:13      阅读:93      评论:0      收藏:0      [点我收藏+]

1.在进行jdbc与mysql连接的时候应注意,加载驱动的方式根据MySQL版本内容来说 有变化

  5.7版本之前:

  

String driver= "com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/数据库名字";
String user="数据库用户名";
String password="数据库密码";

 

  5.7版本之后:

            String driver= "com.mysql.cj.jdbc.Driver";
            String url="jdbc:mysql://localhost:3306/dbnamel";
            String user="数据库用户名";
            String password="数据库密码";

    注意标红字体,加载驱动语句并不一样

2. MySQL8.0版本之后,连接数据库会有时区不一致的错误

  错误信息:Error querying database.  Cause: 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.

 

此时的解决方法是:

  在控制台进入MySQL

  输入以下命令:

  show variables like ‘%time_zone%‘;

  查看时区信息

  然后输入

  set global time_zone=‘+8:00‘;

    技术分享图片

 

   输入exit退出,然后重新登入数据库并输入命令:

  show variables like ‘%time_zone%‘;

 

 

 

   技术分享图片

 

 此时时区问题就已经解决好了

 

 

 

 

 

JDBD连接MySQL中的驱动与时区问题

原文:https://www.cnblogs.com/mengang/p/11882014.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!