gpt4 book ai didi

java - linux下mysql jdbc驱动和Eclipse : ClassNotFoundexception com. mysql.jdbc.Driver

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:23 28 4
gpt4 key购买 nike

<分区>

有一个与我非常相似的问题,但就我而言,我的构建路径中没有任何重复的 jar,因此该解决方案对我不起作用。我已经在谷歌上搜索了几个小时,但我在那里找到的解决方案都没有真正解决我的问题。我正在为作业创建一个具有一些数据库连接的网站。我正在使用 MySQL 数据库,在 Eclipse 中开发并在 linux 上运行。我不断收到带有以下 JSP 代码的 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>      
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>query the Leader(mysql) </title></head><body>
<%
Connection conn = null;
Statement stat = null;
ResultSet rs = null;

//加载mysql数据库驱动类
Class.forName("com.mysql.jdbc.Driver").newInstance();
//数据库连接URL
String url = "jdbc:mysql://localhost/fams_db";
//数据库用户名
String user="root";
//数据库密码
String pwd="123456";
conn = DriverManager.getConnection(url,user,pwd);
stat=conn.createStatement();
String sql="SELECT * FROM Leader";
rs=stat.executeQuery(sql);
out.print("<table border=2>");
out.print("<tr>");
out.print("<th width=100>"+"LeaderID");
out.print("<th width=100>"+"LeaderName");
out.print("<th width=100>"+"LeaderPwd");
out.print("<th width=100>"+"Type");
out.print("</tr>");
while(rs.next()){
out.print("<tr>");
out.print("<td>"+rs.getInt("LeaderID")+"</td>");
out.print("<td>"+rs.getString("LeaderName")+"</td>");
out.print("<td>"+rs.getString("LeaderPwd")+"</td>");
out.print("<td>"+rs.getInt("Type")+"</td>");
out.print("</tr>");
}
if(rs!=null)
{
rs.close();
}
if(stat!=null)
{
stat.close();
}
if(conn!=null)
{
conn.close();
}
out.print("</table>"); %>
</body> </html>

我不知道为什么!这是我所做的:

1).下载mysql-connector-java-5.1.27-bin.jar.

2) tomcat url:/usr/local/tomcat7 eclipse url:/usr/local/eclipse jdk url:/usr/local/java

3).在 Eclipse 中打开项目属性。

4).运行jsp文件每次我尝试使用 servlet 时,无论我是否有 jar,我都会得到同样的错误。你能帮我解决这个问题吗?我应该把 mysql-connector-java-5.1.27.jar 放在哪里???

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com