JDBC获取连接抛出java.sql.SQLException: The server time zone...

news/2024/5/18 21:42:56 标签: JDBC

今天尝试数据库,代码确实没问题就是给了给这个东西

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.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
	at db.Prepare.main(Prepare.java:22)

后来在大佬们的帮助下得知
数据库时区设置错误。

解决方法:分两种,但原理都是时区设置为当前系统时区

1、在连接数据库语句中的url变量中修改

Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/t_user","root","root");//修改前
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/t_user?serverTimezone=GMT%2B8","root","root");//修改后

2、使用root用户登录mysql,执行以下语句

set global time_zone=’+8:00’;
提示Query OK…即为成功。


http://www.niftyadmin.cn/n/1690027.html

相关文章

谷歌商店输入账号密码后 回到登录界面/闪退

问题&#xff1a; 卸载谷歌所有服务后重下载谷歌三件套&#xff08;换了好多家安装器了&#xff0c;魅族专版&#xff0c;go安装器&#xff0c;小米的&#xff0c;apkpure里也就是谷歌商店里的&#xff0c;都不行&#xff09;后&#xff0c; 输入账号密码&#xff0c;第一次还会…

SWUST OJ 1012哈希表(链地址法处理冲突)

哈希表&#xff08;链地址法处理冲突&#xff09; 1000(ms) 10000(kb) 2676 / 6911 采用除留余数法&#xff08;H&#xff08;key&#xff09;key %n&#xff09;建立长度为n的哈希表&#xff0c;处理冲突用链地址法。建立链表的时候采用尾插法。 输入 第一行为哈西表的长度…

SWUST OJ1065 无向图的连通分量计算

无向图的连通分量计算 5000(ms) 10000(kb) 2555 / 5521 假设无向图G采用邻接矩阵存储&#xff0c;编写一个算法求连通分量的个数。 输入 第一行为一个整数n&#xff0c;表示顶点的个数&#xff08;顶点编号为0到n-1&#xff09;&#xff0c;接下来是为一个n*n大小的整数矩阵…

MySQL服务使用cmd启动与停止服务

MySQL未设置自动启动&#xff0c;在使用时需要手动打开服务&#xff0c;方法如下 mysql服务的启动: 以管理员的身份运行cmd命令窗口,输入命名 net start mysql 提示&#xff1a;必须使用管理员身份运行cmd 如果不是以管理员的身份运行cmd,会提示如下错误 mysql服务的停止: 以…

SWUST OJ 1075 求最小生成树(Prim算法)

求最小生成树(Prim算法&#xff09; 我对提示代码做了简要分析&#xff0c;提示代码大致写了以下几个内容 给了几个基础的工具&#xff0c;邻接表记录图的一个的结构体&#xff0c;记录Prim算法中最近的边的结构体&#xff0c;记录目标边的结构体&#xff08;始末点&#xff…

使用onclick/表单submit跳转到其他页面

使用onclick 如果是本页显示可以直接用location,方法如下&#xff1a; - onclick"javascript:window.location.hrefURL"- onclick"locationURL"- onclick"window.location.hrefURL?id11"如果页面中有frame可以将在location前面添加top.mainfr…

Spring ApplicationContext 容器

Spring ApplicationContext 容器 Application Context 是 BeanFactory 的子接口&#xff0c;也被成为 Spring 上下文。 Application Context 是 spring 中较高级的容器。和 BeanFactory 类似&#xff0c;它可以加载配置文件中定义的 bean&#xff0c;将所有的 bean 集中在一起…

使用Spring实例化Bean的方法以及Bean取别名

一、通过构造方法实例化Bean bean中加构造方法 public class Bean1 {public Bean1() {System.out.println("Bean1构造方法.Bean1");} }xml中配置Bean <bean class"main.java.jirath.spring.class05.Bean1" id"bean1"></bean>采用…