当前位置: 首页 > 知识库问答 >
问题:

如何解决Java EE项目中的时区错误?[副本]

经福
2023-03-14

我知道这个问题不是第一次讨论,但他们没有帮助我,请帮助(最好是详细的)。我已经在intellij IDEA上创建了一个EE web项目。与MySQL连接(下图),然后在index.jsp中编写此代码

    <%
try
{
    Class.forName("com.mysql.jdbc.Driver"); //load driver
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbuser","root","root"); //create connection
    
    if(request.getParameter("btn_login")!=null) //check login button click event not null
    {
        String dbemail,dbpassword;
        
        String email,password;
        
        email=request.getParameter("txt_email"); //txt_email
        password=request.getParameter("txt_password"); //txt_password
        
        PreparedStatement pstmt=null; //create statement
        
        pstmt=con.prepareStatement("select * from login where email=? AND password=?"); //sql select query 
        pstmt.setString(1,email);
        pstmt.setString(2,password);
        
        ResultSet rs=pstmt.executeQuery(); //execute query and store in resultset object rs.
        
        if(rs.next())
        {
            dbemail=rs.getString("email");
            dbpassword=rs.getString("password");
            
            if(email.equals(dbemail) && password.equals(dbpassword))
            {
                session.setAttribute("login",dbemail); //session name is login and store fetchable database email address
                response.sendRedirect("welcome.jsp"); //after login success redirect to welcome.jsp page
            }
        }
        else
        {
            request.setAttribute("errorMsg","invalid email or password"); //invalid error message for email or password wrong
        }
        
        con.close(); //close connection 
    }
    
}
catch(Exception e)
{
    out.println(e);
}
%>

运行后我出现了这个错误

“无法识别服务器时区值'ãåííàëüíà+±çèè(çèüà)'或代表多个时区。如果要利用时区支持,必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更指定的时区值。”

附注:在Itellej中,时区是utc,我也尝试在mysql中更改

SET @@global.time_zone = '+00:00';

共有1个答案

那弘
2023-03-14
 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbuser","root","root"); //create connection

必须重写到

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbuser?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root","root"); //create connection

这篇文章很有帮助

 类似资料: