Getting ClassNotFoundException error.
I am working in eclipse and using Jboss-server4.2. Even after adding external mysql-connector jar in build path I am getting the error classnotfoundexception. Even I have tried to place mysql-connector jar inside /web-inf/lib folder.
My-Code looks like
Code :
public class Auth extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/HTML");
PrintWriter out = response.getWriter();
String uname = request.getParameter("uname");
String pass = request.getParameter("pass") ;
try{
Class.forName("com.mysql.jdbc.Driver");
out.println("Driver Loaded");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/j2ee","root","root");
out.println("Connction Established");
PreparedStatement pr = con.prepareStatement("insert into user values(?,?)");
pr.setString(1, uname);
pr.setString(2, pass);
int x = pr.executeUpdate();
if(x>0)
{
out.println("Success");
out.println(uname + " thanks!!");
out.println("Your password: "+ pass);
}
else
out.println("Failed");
}
catch(SQLException e){
out.println(e);
}
catch(ClassNotFoundException f){
out.println(f);
}
}
}
Re: Getting ClassNotFoundException error.
Re: Getting ClassNotFoundException error.
Read the docs for the JBoss server you are using - you need to place external libraries in the appropriate location for them to be on the classpath (not sure about this version, but in other versions its the server/default/lib/ directory)