I'm new to JSP, so I'm playing around with it a bit. I've created a Maven project in Intellij and imported the dependencies that I need in my pom.xml
, namely mysql-connector
and servlet-api
:
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
<scope>compile</scope>
</dependency>
</dependencies>
I have a JSP file that accesses the local MySQL database using the corresponding Driver.
<%
String url = "jdbc:mysql://localhost:80/DemoJSP";
String username = "root";
String password = "";
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, username, password);
%>
However, when I run the Tomcat server, I get HTTP Status 500
. The cause of this is the line Class.forName("...")
, so the thrown exception is java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
. I have tried thousands of Maven reimports, but nothing helps. Is there anything that I'm missing?
P.S.: similar questions like How to use Maven to Create JSP + Servlet + TOMCAT + MySQL or Where do I have to place the JDBC driver for Tomcat's connection pool? do not solve my problem.