在Eclipse中使用MySQL遇到了点小问题

如果对Eclipse中配置MySql还有疑问的可以参考一下这篇博客:https://blog.csdn.net/qq_38247544/article/details/80419692

参考菜鸟上的例子的代码如下:

当然,这是修改后没问题后的代码

 package mysqltest;

 import java.sql.*;

 public class Mysql {
// jdbc驱动名以及数据库URL
// static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/javamysql" + "?serverTimezone=GMT%2B8"; // 数据库的用户名与密码,需要根据自己的设置
static final String USER = "root";
static final String PASS = "root"; public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
// 注册JDBC驱动
Class.forName("com.mysql.jdbc.Driver"); // 打开链接
System.out.println("连接到数据库……");
conn = DriverManager.getConnection(DB_URL, USER, PASS); // 执行查询
System.out.println("实例化statement对象……");
stmt = conn.createStatement();
String sql;
sql = "SELECT id, name, url FROM websites";
ResultSet rs = stmt.executeQuery(sql); // 展开结果集数据库
while (rs.next()) {
// 通过字段检索
int id = rs.getInt("id");
String name = rs.getString("name");
String url = rs.getString("url"); // 输出数据
System.out.print("ID:" + id);
System.out.print(",站点名:" + name);
System.out.println(",站点URL:" + url);
} // 完成后关闭
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
// 处理 JDBC错误
se.printStackTrace();
} catch (Exception e) {
// 处理Class.forname 错误
e.printStackTrace();
} finally {
// 关闭资源
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
} // 什么都不做
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
System.out.println("Goodbye!");
}
}

遇到的问题如下:

原来是因为使用最新的驱动包中`com.mysql.jdbc.Driver'类已经过时,新的`com.mysql.cj.jdbc.Driver'通过SPI自动注册,不再需要手动加载驱动类)

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.

但是后面还有一个如下的问题:

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.

找到了这篇博客

需要在数据库 URL中设置serverTimezone属性:(就是代码第八行)

static final String DB_URL = "jdbc:mysql://localhost:3306/RUNOOB" + "?serverTimezone=GMT%2B8";  这里的 GMT%2B8 代表是东八区。(虽然不太明白为啥要加这个)

jdbc:mysql://localhost:3306/javamysql  端口号后面是你的数据库

最后问题解决了,如果有遇到相同问题的小伙伴可以参考一下!

Eclipse中使用MySql遇到: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 o的更多相关文章

  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

    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb ...

  2. The driver is automatically registered via the SPI and manual loading of the driver class....

    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb ...

  3. spring-boot 再添加mysql启动器的时候报错, The driver is automatically registered via the SPI and manual loading of the driver class....

    mysql驱动更新迭代之后驱动,稍微有点变化: com.mysql.jdbc.Driver (变化为) --> driver-class-name: com.mysql.cj.jdbc.Driv ...

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

    简单介绍 声明:使用JDK9.MYSQL8.idea 报错处理 报错信息如下 原因 提示信息表明数据库驱动com.mysql.jdbc.Driver已经被弃用了.应当使用新的驱动com.mysql.c ...

  5. spingboot启动报驱动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 th

    原因: springboot应用了最新的驱动com.mysql.cj.jdbc.Driver,这个驱动需要用mysql-connector-java包的6.x版本才可以, 而mysql-connect ...

  6. mysql 问题 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb

    异常错误:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.c ...

  7. JDBC连接数据库报错:Loading class `com.mysql.jdbc.Driver'. This is deprecated.

    使用JDBC连接数据库时出现报错, 报错内容:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver cla ...

  8. com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别 serverTimezone设定

    转自: http://blog.csdn.net/superdangbo/article/details/78732700 com.mysql.jdbc.Driver 和 com.mysql.cj.j ...

  9. com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别

    com.mysql.jdbc.Driver 是 mysql-connector-java 5中的,com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的 ...

随机推荐

  1. no matching editors or conversion strategy found

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionM ...

  2. DOS下读取PCI配置空间信息的汇编程序(通过IOCF8/IOCFC)

    汇编程序编写的读取PCI配置空间信息的代码(通过IOCF8/IOCFC): ;------------------------------------------------ ;功能: 读取PCI 配 ...

  3. Prometheus监控学习笔记之prometheus的federation机制

    0x00 概述 有时候对于一个公司,k8s集群或是所谓的caas只是整个技术体系的一部分,往往这个时候监控系统不仅仅要k8s集群以及k8s中部署的应用,而且要监控传统部署的项目.也就是说整个监控系统不 ...

  4. python2.7安装mysql-python

    环境:python2.7.14+mysql-python-1.2.3.win-amd64-py2.7.exe 安装版本许参照解释器版本,有64和32位之分,如果安装错误版本,则运行时会报错:Impor ...

  5. Android - Resource 之 Layout 小结

    Layout定义了一个Activity的UI框架,或者是一个UI的组件. 文法如下: ?xml version="1.0" encoding="utf-8"?& ...

  6. HTTP协议和XMPP协议、MQTT协议

    应用层协议:每个应用层的都是为了解决某一类应用问题.而问题的解决又必须通过位于不同主机中的多个应用进程之间的通信和协同工作来完成.应用进程之间必须遵守严格的规则.应用层协议应当定义如下几个: 应用进程 ...

  7. Plantuml画图工具

    1,Plantuml画图工具 安装指南: Mac sublimetext http://blog.csdn.net/zhangjikuan/article/details/53365730 win i ...

  8. HDU - 1849 Rabbit and Grass 【Nim博弈】

    Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛公园,不去和AC ...

  9. FJNU2018低程F jq解救fuls (贪心乱搞)题解

    题目描述 一天fuls被邪恶的"咕咕咕"抓走了,jq为了救fuls可谓是赴汤蹈火,费了九牛二虎之力才找到了"咕咕咕"关押fuls的地方. fuls被关在一个机关 ...

  10. 【做题】sgu189 Perl-like Substr——dark模拟

    注:这篇博客纯属为凑篇数而生. 题面较长,幸运的是,网上给出了相当不错的翻译. 需要支持的操作很简单,即对子串提取.赋值和输出,且对时间复杂度没有要求.换言之此题有成为块链毒瘤题的潜质.难点在于输入的 ...