1

I know that this question was discussed not for the first time, but they did not help me, please help (preferably in detail). I have created an EE web project on intellij IDEA. Connected with MySQL (photo below) Then I write this code in 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);
}
%>

connection to DB

And after running I have this error

"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."

P.S: In Itellej IDEA time zone is UTC , and I'm also tried change in mysql

SET @@global.time_zone = '+00:00';
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi check [this](https://stackoverflow.com/a/27276523/10606400) answer might help . – Swati Oct 18 '20 at 07:14
  • @Swati I looked, but how exactly do I add to my code? Can you help with this – Билолбек Атабеков Oct 18 '20 at 07:22
  • Change your connection string like `"jdbc:mysql://localhost:3306/dbuser?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"` and see if that works .. Also that link has many suggesstion try other as well as see. – Swati Oct 18 '20 at 07:31
  • @Swati but in this line we must write also passwort to local server, so where I should write? "jdbc:mysql://localhost:3306/dbuser?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC" – Билолбек Атабеков Oct 18 '20 at 07:38
  • Just change `jdbc:mysql://localhost:3306/dbuser` to `jdbc:mysql://localhost:3306/dbuser?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC` in your code where you are passing connection string . Also ,password and username will be same no need to make any changes there. – Swati Oct 18 '20 at 07:43
  • @Swati Thank you very much, you helped so much. Pardon me. – Билолбек Атабеков Oct 18 '20 at 07:54

1 Answers1

0
 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbuser","root","root"); //create connection

must to rewrite to

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

This post was helpful