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

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

  5.7版本以前:mysql

  

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

 

  5.7版本以后:sql

            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.url

 

此时的解决方法是:spa

  在控制台进入MySQLcode

  输入如下命令:server

  show variables like '%time_zone%';blog

  查看时区信息

  而后输入

  set global time_zone='+8:00';

    

 

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

  show variables like '%time_zone%';

 

 

 

   

 

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

相关文章
相关标签/搜索