吴裕雄--天生自然 JAVA开发学习:解决java.sql.SQLException: The server time zone value报错

这个异常是时区的错误,因此只你需要设置为你当前系统时区即可,解决方案如下:

import java.sql.Connection ;
import java.sql.DriverManager ;
import java.sql.SQLException ;
public class Test{
    // 定义MySQL的数据库驱动程序
    public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver" ;
    // 定义MySQL数据库的连接地址,taobao是数据库名称
    //后面+"?serverTimezone=GMT%2B8"是时区设置
    public static final String DBURL = "jdbc:mysql://localhost:3306/taobao"+"?serverTimezone=GMT%2B8";
    // MySQL数据库的连接用户名
    public static final String DBUSER = "root" ;
    // MySQL数据库的连接密码
    public static final String DBPASS = "admin" ;
    public static void main(String args[]){
        Connection conn = null ;        // 数据库连接
        try{
            Class.forName(DBDRIVER) ;    // 加载驱动程序
        }catch(ClassNotFoundException e){
            e.printStackTrace() ;
        }
        try{
            conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
        }catch(SQLException e){
            e.printStackTrace() ;
        }
        System.out.println("连接成功");
        System.out.println(conn) ;    // 如果此时可以打印表示连接正常
        try{
            conn.close() ;            // 数据库关闭
        }catch(SQLException e){
            e.printStackTrace() ;
        }
    }
};

原文地址:https://www.cnblogs.com/tszr/p/12208658.html