繁体   English   中英

Tomcat 通过 Maven 导入后找不到 JDBC 驱动程序

[英]Tomcat does not find JDBC Driver after importing via Maven

我是 JSP 的新手,所以我正在玩弄它。 我在 Intellij 中创建了一个 Maven 项目,并在我的pom.xml中导入了我需要的依赖项,即mysql-connectorservlet-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>

我有一个 JSP 文件,它使用相应的驱动程序访问本地 MySQL 数据库。

<%
    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);
%>

但是,当我运行 Tomcat 服务器时,我得到HTTP Status 500 The cause of this is the line Class.forName("...") , so the thrown exception is java.lang.ClassNotFoundException: com.mysql.jdbc.Driver . 我已经尝试了数千次 Maven 重新导入,但没有任何帮助。 有什么我想念的吗?

PS: 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? 不要解决我的问题。

在 url 中尝试localhost端口3306而不是 80。

如果您在时区出现错误,请使用以下字符串:


String url = "jdbc:mysql://127.0.0.1:3306/DemoJSP";
String timezone = "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
String username = "root";
String password = "";
Connection connection = DriverManager.getConnection(url + timezone, username, password);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM