Insert Data To Database In JSP

 <%-- 

    Document   : insertData

    Created on : 4 Mar, 2021, 5:09:48 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>Insert To Database</title>

    </head>

<body>

    <h1> Insert To Database</h1>



<% try

    {

       //this is for mysql database(Xampp)

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

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


        Statement st=con.createStatement();

        String q="insert into user values (2,'kanha')";


        int i =st.executeUpdate(q);


        if(i>0){

            out.println("inserted Successfully");

        }

    }

    catch(Exception e)

    {

        out.println(e);

    }

    

%>

</body>


</html>

Post a Comment

0 Comments