IDEA连接MySql8.0的一些坑

IDEA连接MySql8.0的一些坑

1. maven配置

当maven更改为阿里云镜像后,默认是会下载mysql驱动包

具体在pom.xml的配置如下:

<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
</dependencies>

2. 注册驱动

直接运行时可能会报以下错误:

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

这是因为新版MySQL不推荐使用 com.mysql.jdbc.Driver ,所以注册驱动时改为如下即可

DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());

3.连接数据库

这里以数据库名为 test 为例

当直接使用jdbc:mysql://localhost:3306/***时会跳出以下错误

Exception in thread “main” 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.

我一开始是改为之前那样子带一个修改字符集的参数

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8

结果还是不行,原因是到MySQL8.0相应的驱动包也发生了更新,所以找到了一种新的方法
,参数在原来的基础上加上&useSSL=false&serverTimezone = GMT,如下

jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone = GMT

连接成功

注意:在xml文件中是不允许用&符号的,所以应该用&amp;替代

jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;serverTimezone = GMT

4. jdk版本低

数据库测试调试后,发现报黄色错误,输入影响运行但是还是解决下

错误信息为

Warning:java: 源值1.5已过时, 将在未来所有发行版中删除

Warning:java: 目标值1.5已过时, 将在未来所有发行版中删除

解决方法

  • 修改Maven的Settings.xml文件添加如下内容

    <profile>
    <id>jdk-1.8</id>
    <activation>
    <activeByDefault>true</activeByDefault>
    <jdk>1.8</jdk>
    </activation>
    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
    </profile>
  • 在项目的pom.xml文件中添加

    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
  • 打开项目配置,设置Modules的Language Level为”8”

  • 最后按”Ctrl+Alt+S”打开设置,搜索”Java Compiler”,将默认jdk和当前modual的jdk版本切换为1.8即可
posted @   konley  阅读(214)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
点击右上角即可分享
微信分享提示