Re: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Posted by:
Rahul Shingala ()
Date: February 21, 2011 04:32AM
I have the following error when i try to run Java file which has connections for MYSQL.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
My program coding is
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Connectivity extends HttpServlet{
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection connection=null;
try{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("Select * from emp_sal");
while(rs.next()){
pw.println("EmpName" + " " + "EmpSalary" + "<br>");
pw.println(rs.getString(1) + " " + rs.getString(2) + "<br>");
}
}
catch (Exception e){
pw.println(e);
}
}
}