0

i am creating simple crud using jsp servlet connect with mysql database. i ran into the problem with ClassNotFoundException: com.mysql.jdbc.Driver i successfully added the mysql driver i attached with the screenshot image below.please have a look.

enter image description here

what i tried the code i attached below.

@WebServlet("/addServlet")
public class addServlet extends HttpServlet {
    
       

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        PreparedStatement st1=null;
        Connection con; 
      
            
        PrintWriter out = response.getWriter();

         String  sname =request.getParameter("sname");
         String  course =request.getParameter("course");
         String addr =request.getParameter("address");
         String mobile =request.getParameter("mno");
         
        
        try
        {
        
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost/lblschool", "root","");   
        String query ="insert into student(sname,course,address,mno)values(?,?,?,?)";
        st1= con.prepareStatement(query);

        st1.setString(1, sname);
        st1.setString(2, course);
        st1.setString(3, addr);
        st1.setString(4, mobile);
        int k = st1.executeUpdate();


        if(k ==1)
        {
            out.println("Thanks for registration ......");
            String query2 = "select max(reg_id) from students";
            
            Statement st1s = con.createStatement();
            ResultSet rs1 = st1s.executeQuery( query2); 
            rs1.next( );
            String reg_No = rs1.getString(1);
            out.println("Your registration id is " + reg_No);
            
         }
            else
            {
            out.println("Cant' update");
            }
         }
        
        catch(Exception ee)
          {
            System.out.println(ee.toString());
            }

        }
        
        

    }
gaya ram
  • 21
  • 2
  • 8

1 Answers1

-1

Try using this class:

com.mysql.cj.jdbc.Driver
mr.SoSerious
  • 121
  • 1
  • 9