There is a VERY similar question to mine but in my case I don't have any duplicate jars in my build path, so the solution does not work for me. I've searched google for a couple of hours now, but none of the solutions I've found there actually resolve my issue. I'm creating a web site with some database connectivity for a homework. I'm using a MySQL database, developing in Eclipse and running on linux. I keep getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver with the following JSP code:
<%@ 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>
I can't figure out why! Here is what I did:
1).Download 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).Opened the project properties in Eclipse.
4).run the jsp file Every time I attempt to use the servlet I get the same error regardless if I have the jar in there or if I don't. Could you help me figure this out? Where should I put the mysql-connector-java-5.1.27.jar???