[新人向]刚学数据库的新手使用高版本MySQL的几大坑!!!

一、在使用mysql的jdbc驱动最新版(6.0+)版本时驱动方式更改

MySQL5:com.mysql.jdbc.Driver
MySQL6+:com.mysql.cj.jdbc.Driver
否则会出现以下错误: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的jdbc驱动最新版(6.0+)版本时,数据库和系统时区差异引起的问题

MySQL5:jdbc:mysql://localhost:3306/库名
MySQL6+:jdbc:mysql://localhost:3306/库名?serverTimezone=UTC&characterEncoding=utf-8
否则会出现以下错误: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.在这里插入图片描述

三、正确示范

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 测试跟数据库建立连接
 * @author 18072
 *
 */
public class Demo01 {
	public static void main(String[] args) {
		//加载驱动类
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			//建立连接
			Connection conn = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/pipi?serverTimezone=UTC&characterEncoding=utf-8","root","123456");
			System.out.println("连接成功!!!");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
}

在这里插入图片描述

四、最简单的解决方案(不推荐)

更换5.5版本的MySQL,操作简单,但是作为新时代的程序猿还是得与时俱进,紧跟步伐!!!

我是一个疯狂踩坑的程序猿Pipi酱~

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值