java - 在 Eclipse 中使用 JBDC 驱动程序给了我一个 classNotFoundException
问题描述
这是我第一次使用 JSP。我已经设置了一个 tomcat 9.0.8 服务器,我正在使用 Java 8.5,以及 MySQL 8.0.11,我在 Windows 10 上使用 Eclipse EE。
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
我遇到了这个错误,而且我看到很多其他人问过同样的问题,所以我尝试了很多解决方案,但都没有奏效。我已经下载了 mysql-connector-java-8.0.11这些是我迄今为止尝试过的一些解决方案:
<%@ page import = "com.mysql.jbdc.Driver %>
在文件开头添加- 都试过
Class.forName("com.mysql.jdbc.Driver");
了Class.forName("com.mysql.jdbc.Driver").newInstance();
将 JAR 文件添加到:
- apache-tomcat-9.0.8\lib
- ..\eclipse-workspace\ProjectFolder
- ..\eclipse-workspace\ProjectFolder\WEB_INF\lib\
在项目的 BUILD PATH 中添加为外部 JAR
请帮忙。我不知道还能做什么。
编辑:这是我当前的代码。
<%@
page import="java.sql.*, javax.sql.*"
%>
<%
String name = request.getParameter("name");
String age = request.getParameter("age");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "user", "pass");
Statement s = con.createStatement();
%>
<html>
<head>
<title> Processing </title>
</head>
<body>
Hello <%=name%>
</body>
</html>
编辑:
我通过在构建路径选项的“订单和导出”设置中选择 JAR 来使其工作。
解决方案
在 Eclipse 中:
- 右键单击您的项目
- 选择属性
- 选择 Java Build Path(从打开的对话框的左侧边栏中)
- 单击库(在右侧边栏上)
- 单击添加外部 JAR
- 选择您的 MySQL 连接器 Jar 并单击打开。
现在应用并重新运行您的代码。
推荐阅读
- google-sheets - 根据复选框勾选显示不同的值
- php - PHP - 转换为 UTF-8 / 多语言欧洲 Subset-1
- javascript - 如何根据其他面板制作面板的高度?
- git - 如何在特定历史位置插入提交并重写所有路径的历史?
- javascript - javascript中两个看似相等的字符串不相等
- java - 引用来自 fx:define 块的多行字符串变量
- java - RestHighlevelClient 切片滚动不起作用
- amazon-web-services - AWS Neptune 的 Django 数据库驱动程序
- java - 如何处理 Java HTTP Server 上不匹配/不需要或有效的请求?
- react-i18next - 下拉和 react-i18next