gpt4 book ai didi

java - 无法将 Java 项目与 MySQL Workbench 连接(TIMEZONE 错误)

转载 作者:行者123 更新时间:2023-12-02 01:09:00 25 4
gpt4 key购买 nike

我有作业,我需要使用mysql和java。我需要访问 mysql 工作台上的表、employeee 表,我下载了驱动程序并做好了每件事,但我收到错误:

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.*;

public class Driver {
public static void main(String[] args) {
Connection myConn = null;
try {
myConn =(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/employee",
"root", "root");

//create statement
Statement myStmt = myConn.createStatement();
if (myConn !=null) {
System.out.println("connection succsesful");
//excute sql query
ResultSet myRs = myStmt.executeQuery("select * from project");

//process the result set
while(myRs.next()) {
System.out.println(myRs.getString("DNUM") + "," + myRs.getString("PNUMBER"));
}
}
}
catch(Exception exc) {
System.out.println("connection failed");
exc.printStackTrace();
}
}
}

最佳答案

DriverManager.getConnection 的第一个参数从 "jdbc:mysql://localhost:3306/employee" 更改为 "jdbc:mysql://本地主机:3306/employee?serverTimezone=UTC

如果您不想使用 UTC,请将 UTC 替换为您希望数据库记录/显示时间的时区。

关于java - 无法将 Java 项目与 MySQL Workbench 连接(TIMEZONE 错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59637415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com