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即可
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值