MySQL Forums
Forum List  »  Microsoft SQL Server

solution for java.lang.ClassNotFoundException: com.mysql.jhdbc.Driver !!!! problem
Posted by: karthicraj rajendran
Date: September 09, 2009 12:11PM

Hi friends

you have problem in Jdbc and Mysql connection in MyEclipse v5.???

Add the following jar file from Mysql folder

Right click in package and select Biultpath then select
addExternalarchieve file ..like

D:\Program Files\MySQL\MySQL Tools for 5.0\java\lib

lib have some jar files add to


now you add the jar file for ur IDE cool and check ur code

Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/karthicraj","mysql","mysql");



Try ur self
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Connection.*;


public class EmpDetail extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException
{
Connection con;
Statement stm;
PreparedStatement pstm;



String s1=request.getParameter("s1");
String s2=request.getParameter("s2");
String s3=request.getParameter("s3");

PrintWriter pw=response.getWriter();



String name=request.getParameter("name");
int age=Integer.parseInt(request.getParameter("age"));
int salary=Integer.parseInt(request.getParameter("salary"));

pw.println("<HTML>");
pw.println("<BODY>");



if(s1!=null)
{

try
{


Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/karthicraj","mysql","mysql");
System.out.println ("Database connection established");
System.out.println("hi");
stm=con.createStatement();
String strQry="Insert into ram(name,age,salary)values(?,?,?)";
pstm=con.prepareStatement("Insert into ram(name,age,salary)values(?,?,?)");
System.out.println("Ready for Insert");
pstm.setString(1,name);
pstm.setInt(2,age);
pstm.setInt(3,salary);
pstm.executeUpdate();
System.out.println("Updated");
pstm.close();
con.close();

pw.println("thank u for Inserting data");
RequestDispatcher dispatcher = request.getRequestDispatcher("EmpDetail.html");
dispatcher.include(request, response);
}
catch(ClassNotFoundException e)
{
pw.println(e);
}
catch(SQLException e)
{
pw.println(e);
}

}

else if(s2!=null)
{

try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/karthicraj","mysql","mysql");
System.out.println("connection success 1");
stm=con.createStatement();

String strQry="update ram set age=?,salary=? where name=? "; // and age=?";

pstm=con.prepareStatement(strQry);

pstm.setInt(1,age);
pstm.setInt(2,salary);

pstm.setString(3,name);
//pstm.setInt(4,age);

pstm.executeUpdate();

pstm.close();
con.close();

pw.println("thank u for updating data");
RequestDispatcher dispatcher = request.getRequestDispatcher("EmpDetail.html");
dispatcher.include(request, response);

}
catch(ClassNotFoundException e)
{
pw.println(e);
}
catch(SQLException e)
{
pw.println(e);
}

}

else
{

try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/karthicraj","mysql","mysql");
stm=con.createStatement();



stm.executeUpdate("delete from ram where name='"+name+"' and age="+age);


stm.close();
con.close();
pw.println("thank u for Deleting data");
RequestDispatcher dispatcher = request.getRequestDispatcher("EmpDetail.html");
dispatcher.include(request, response);

}
catch(ClassNotFoundException e)
{
pw.println(e);
}
catch(SQLException e)
{
pw.println(e);
}

pw.println("</BODY>");
pw.println("</HTML>");

}


}
}

Options: Reply• Quote


Subject
Written By
Posted
solution for java.lang.ClassNotFoundException: com.mysql.jhdbc.Driver !!!! problem
September 09, 2009 12:11PM


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.