MySQL Forums
Forum List  »  Microsoft SQL Server

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

Options: ReplyQuote


Subject
Written By
Posted
Re: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
February 21, 2011 04:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.