Welcome to “Algorithms and the Beauty of Programming” ↑ pay attention to us!

This article was first published on the wechat official account “Beauty of Algorithms and Programming”. Welcome to follow and learn more about this series of blogs in time.

When we use Idea to write JavaWeb, it is inevitable to use MySQL (database) data to make the page “move”. However, when we use Java to connect to MySQL, there is often a class that we need to use. This class is:

Class.forName(“com.mysql.jdbc.Driver”)

HTTP Status 500 — Internal Server Error: HTTP Status 500 — Internal Server Error: HTTP Status 500 Here are my solutions to these three questions. Please let me know if there are any mistakes:

1 time zone

The first is the time zone issue, because the database is stored with time stamps, so sometimes the local time zone and the server time zone conflict. The following code is an error:

javax.servlet.ServletException: Java. SQL. SQLException: The server time zone value ‘й ׼ ʱ’ isunrecognized or represents more than one time zone, You must configure eitherthe server or JDBC driver (via the serverTimezone configuration property) touse a more specifc time zone value if you want to utilize time zone support.

This problem is easy to solve. The server time zone problem occurs when mysql is connected to the server. In this case, we can solve this problem by using the program to generate UTC time, the code is as follows:


jdbc:mysql://localhost:3306/sctu_javaweb_2018? serverTimezone=UTC

(Time zone problems can be solved by adding utc after the connection. Utc is the universal time zone.)

Then the time zone problem can be solved.

2 the password

The second problem is the password problem, sometimes we remember the wrong password may cause us to access the mysql database, so we need to remember our password.

The error code is as follows. If the error code appears, all you need to do is change your login password.

javax.servlet.ServletException: java.sql.SQLException:Access denied for user ‘root’@’localhost’ (using password: YES)

3 Class NoFound

The third problem is that tomcat cannot recognize the class we need as mentioned above. The reason for this failure is that your dependency is not built properly, so the system cannot recognize it. The error code is as follows:

javax.servlet.ServletException:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:667)

         org.apache.jsp.index_jsp._jspService(index_jsp.java:255)

         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

         javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)

         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)

         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)

         javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

         org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

To solve this problem, we need to build the dependency, and then add the project in Tomcat, so that the general can recognize mysql class, the specific operation is as follows:

Select your project in Modules (add one to it or select the root directory), select Dependencies on the right side, and click the “+” sign to the right:

Select the first one to add JARs to your project, establish project dependencies, and then select on the right

Artifacts:

Click “+” to add the deployment package of the project and select the exploded WAR package. In the output layout, note that the LIB under web-INF needs the JAR deployed by the project. Since we are solving problems with the database, we need the jar package of MySQL. Then our project dependencies are set up and Tomcat can find (recognize) com.mysql.jdbc.driver for MySQL. Then configure tomcat. If it is configured, reconfigure it. See the diagram for configuration.

Click the triangle shown in the picture, then click Edit Configurations–> Green plus –> If it’s not in the list –> Click 33 items more comedy-and keep looking

On the right, note the two red lines: the first line is the tomcat directory address, and the second line is the Java JRE address.

Add your project to Deployment again:

Save the changes and run, which roughly resolves tomcat’s inability to find JDBC.

Some friends recommend that if you can’t identify it, you can add Tomcat to the system environment. This method has not been tested before, I wonder if it can work, you may want to try.

Note: This article is submitted by Hu Ganhang, majoring in information Management and information system, Grade 16, Sichuan Tourism University.

\

More interesting articles:


Sichuan Tourism Institute Where2Go team



Wechat: The beauty of algorithms and programming

Long press to identify the QR code to follow us!

Tips: Click on the lower right corner of the page “Write a message” to comment, looking forward to your participation! Welcome to forward!