使用Intellij IDEA连接MySQL时遇到的问题,以及相

2020-09-09  本文已影响0人  Still_Climbing

一、驱动下载

到MySQL官网 https://dev.mysql.com/downloads/connector/j/,选择platform independent(平台无关)

驱动官网

这里建议选择第二项进行下载,得到的是zip压缩包,解压之后即可获得驱动

下载

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

解决方法:
顾名思义,就是找不到Mysql的驱动。博主参考网上教程一共尝试了三种方法,分别是:

然而不知道出于什么原因,这里只有第三种方法成功了,在这里分享一下我的做法:

首先在项目中点击右上角的Project Structure图标,对应的快捷键是Ctrl + Alt +Shift + S

步骤1

进入到Project Structure菜单后依次按照下图的步骤进行设定

步骤2

最后选择自己本地下载好的MySQL驱动jar包即可

步骤3

三、Loding class 'com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.

解决方法:
将MySQL的驱动类由原来的com.mysql.jdbc.Driver改成com.mysql.cj.jdbc.Driver

private static String driver = "com.mysql.jdbc.Driver";

四、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的URL后面加上?serverTimezone=UTC

private static String url = "jdbc:mysql://localhost/StudentScore" +
            "?characterEncoding=UTF-8&serverTimezone=UTC";

五、Unknown column 'xxx' in 'field list'

解决方法:
出现这个问题时可以考虑从以下方面入手:

上一篇 下一篇

猜你喜欢

热点阅读