Java使用8.0以上的jar包连接MySQL数据库遇到的问题

MySQL驱动jar包传送门
我用的是8.0.1的jar包,当时是报了两个错。

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

这个报错很长,但就是想告诉你一件事,驱动换了!
(通过红色的字可以看出)

//这是原来的写法
Class.forName("com.mysql.jdbc.Driver");    
 
//这是8.0以上的写法
Class.forName("com.mysql.cj.jdbc.Driver");     

不过到了5的版本以上就可以省略这句了。

2.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.

emmmm。。。。这个报错更长了,但其实也是写法上出现了问题。

//这是原来的写法
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名", "root", "密码");   

//修改之后的写法    
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC", "root", "密码");    //区别在于在数据库名之后加上了?serverTimezone=UTC    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值