Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java-EDT时区连接到DB_Java_Mysql_Selenium_Jdbc - Fatal编程技术网

如何在Java-EDT时区连接到DB

如何在Java-EDT时区连接到DB,java,mysql,selenium,jdbc,Java,Mysql,Selenium,Jdbc,我在尝试执行自动化测试时遇到了一个问题。 我想连接到DB并执行select查询。 直到现在,当DB处于UTC时间时,一切正常。 然而,今天DB团队将DB时区更改为edt 这是我的代码: public class DBSupport { private final String ID = "id"; private final String CLASS = "com.mysql.cj.jdbc.Driver"; DBConfiguration dbConfiguratio

我在尝试执行自动化测试时遇到了一个问题。 我想连接到DB并执行select查询。 直到现在,当DB处于UTC时间时,一切正常。 然而,今天DB团队将DB时区更改为edt

这是我的代码:

public class DBSupport {


    private  final String ID = "id";
   private final String CLASS = "com.mysql.cj.jdbc.Driver";
   DBConfiguration dbConfiguration;


   public String getUserIdFromDB(String newmail) throws Exception {
       dbConfiguration = new DBConfiguration();
       String query = "select id from users where email = '" + newmail + "' limit 1;";
       String userId = null;
       Class.forName(CLASS);
       Connection conn = DriverManager.getConnection(dbConfiguration.getUrl(), dbConfiguration.getUserName(), dbConfiguration.getPassword());
       Statement stmt = conn.createStatement();
       ResultSet rowResult = stmt.executeQuery(query);
       if (rowResult.next()) {
           userId = rowResult.getString(ID);
           System.out.println(userId);
       }
       conn.close();
       return userId;
   }




}
这是我得到的一个例外:

java.sql.SQLException: The server time zone value 'EDT' 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)
这是构建渐变中的值

runtimeOnly 'mysql:mysql-connector-java:8.0.17'
当我在数据库中运行此命令时

SELECT @@system_time_zone ;
结果是

EDT
我不需要时区来进行测试,只是为了连接到数据库。 直到昨天,在UTC,它仍然有效。 我应该为我的功能添加什么?
关于

您可以使用连接字符串URL中的
serverTimeZone
参数覆盖时区,如下所示

"jdbc:mysql://localhost/test?serverTimezone=UTC"

请参见

多亏了roninjoe,这才是解决方案

Connection con = DriverManager.getConnection("jdbc:mysql://DB_IP:DB_PORT/DB_NAME?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","db_user","db_password"));

我在代码中没有看到
EDT
,也没有在代码中看到任何日期时间处理。日期时间与查询电子邮件地址和获取用户ID有什么关系?我不知道,但这是个例外。我不想从日期算起什么,只想连接到db,这是个例外