MySQL笔记——JDBC连接MySQL遇到的问题

我用的是IDEA,先是按照步骤下载jar包,然后在WEB-INFO目录下新建一个lib目录,将下好的jar包导入,然后开始连接MySQL。

public static final String URL = "jdbc:mysql://localhost:3306/test";
    public static final String USER = "root";
    public static final String PASSWORD = "*******";

    public static void main(String[] args) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        //1.加载驱动程序
        Class.forName("com.mysql.jdbc.Driver");
        //2. 获得数据库连接
        Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
    }

运行时却发生如下错误:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver...

解决办法:
file-->Project Structure-->Modules-->Dependencies-->选中-->最右边的加号-->JARs or directories...-->导入下载的jar包。

再次运行却发生时区问题:

Reason: Could not get JDBC Connection; nested exception is 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.

解决办法:
dos界面打开mysql,输入如下命令就OK了:


MySQL笔记——JDBC连接MySQL遇到的问题_第1张图片
时区问题

感谢

来源:《关于idea第一次如何载入JDBC驱动》
链接:https://blog.csdn.net/weixin_38627405/article/details/73824733

来源:《【时区问题】连接MySQL时错误The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone》
链接:http://www.cnblogs.com/sunny3096/p/9259274.html

你可能感兴趣的:(MySQL笔记——JDBC连接MySQL遇到的问题)