0

HI..
I want to create an webpage such that when user will enter their username and password,the data will be stored in a database(I am using MySQL).I have the code.But when i am trying to run the servlet,its showing following error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 

I have set the classpath of the driver

C:\apache-tomcat-4.1.36\common\lib\servlet.jar;C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar

I think its ok as if i run any jdbc program without using servlet, it is working properly.
So i cant understand what to do..
Please help as soon as possible.
This is servlet code:

import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletInsertingDataUsingHtml extends HttpServlet{
  public void doPost(HttpServletRequest request, HttpServletResponse response)
                                 throws ServletException, IOException{
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
 String JDBC_DRIVER = "com.mysql.jdbc.Driver";        
    String DATABASE_URL = "jdbc:mysql://localhost/sweta_db";

    Connection connection;
    try{
Class.forName( JDBC_DRIVER );
connection = DriverManager.getConnection( DATABASE_URL, "jhtp6", "jhtp6" );
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      pw.println(username);
      pw.println(password);



      PreparedStatement pst = connection.prepareStatement("insert into User values(?,?)");
      pst.setString(1,username);
      pst.setString(2,password);
      int i = pst.executeUpdate();
      if(i!=0){
        pw.println("<br>Record has been inserted");
      }
      else{
        pw.println("failed to insert the data");
      }
    }
    catch (Exception e){
      pw.println(e);
    }
  }
}

Edited by mike_2000_17: Fixed formatting

3
Contributors
7
Replies
8
Views
10 Years
Discussion Span
Last Post by jasimp
0

Welcome...happy to have you!...just remember to post your question in the correct section as shown above!

0

ok..i will try..but what about my prooblem?any solution?please..i need it urgently

0

You need to post it in the correct forum. I do not know the answer but if you post it in the right forum you have a better chance of recieving help.

0

in which forum, i have to paste?please suggest me...

I already answered that question and gave you the links to the right place.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.