zoukankan      html  css  js  c++  java
  • JDBC获取连接时的时间问题

      JDBC获取连接时的时间问题

    附源代码:

            Connection conn=null;
            PreparedStatement psPreparedStatement=null;
            ResultSet rs=null;
            
            try {
                Class.forName("com.mysql.cj.jdbc.Driver");//注意要引入外来mysql包
                conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/hanxiao","root","");
                String sql="select job,sal from emp where sal=?";
                psPreparedStatement=conn.prepareStatement(sql);
                psPreparedStatement.setString(1, "800.00");
                rs=psPreparedStatement.executeQuery();

    出现的问题:

    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:836)

    出现这个问题是时区的问题,要么调整自己电脑的时间,或者在获取连接的url后面加上serverTimezone=GMT,这样就可以运行了

    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/hanxiao?serverTimerzone=GMT","root","");
  • 相关阅读:
    紫书 例题8-18 UVa 1442 (扫描法)
    紫书 例题8-17 UVa 1609 (构造法)(详细注释)
    紫书 例题8-16 UVa 1608 (递归)
    紫书 例题8-15 UVa 12174 (滑动窗口)
    紫书 例题8-14 UVa 1607 (二分)
    紫书 例题8-13 UVa 11093 (反证法)
    紫书 例题8-12 UVa 12627 (找规律 + 递归)
    Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
    CodeForces
    CodeForces 444C 线段树
  • 原文地址:https://www.cnblogs.com/instead-everyone/p/13852353.html
Copyright © 2011-2022 走看看