Update Data To Database In JSP

 <%-- 

    Document   : updateData

    Created on : 4 Mar, 2021, 6:46:43 PM

    Author     : KANHA

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.lang.*" %>

<%@page import="java.sql.*" %>


<!DOCTYPE html>

<html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Update Data Database</title>

    </head>

<body>

    <h1>Update Data Database</h1>


<% try

    {

       //load the driver

        Class.forName("com.mysql.jdbc.Driver");

        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");


        Statement st=con.createStatement();

        String q="update user set name='kanha2' where id=2";


        int i =st.executeUpdate(q);

        

        if(i>0){

            out.println("Updated Successfully");

        }

        else

        {

            out.println("Failed To Update ");

        }

    }

    catch(Exception e)

    {

        out.println(e);

    }

%>

</body>

</html>

Post a Comment

0 Comments