Skip to main content

Featured Post

What’s new in C# 14.0

  Features of C# 14.0  🧩 1️⃣ Field-backed Properties (0:40 – 1:00) Pehla feature hai — Field-backed Properties Ab aapko manually private field likhne ki zarurat nahi. C# 14 mein ek naya contextual keyword aaya hai — field public string Name { get ; set => field = value ?? throw new ArgumentNullException( nameof ( value )); } Yahaan field compiler-generated backing field ko represent karta hai. Validation ya logic likhna ab super easy ho gaya hai! 🧩 2️⃣ Extension Members (1:00 – 1:25) Dusra feature — Extension Members Pehle hum sirf extension methods bana sakte the, ab hum properties , events , aur static members bhi extend kar sakte hain! public static class StringExtensions { public static int WordCount ( this string str) => str.Split( ' ' ).Length; } Ab koi bhi string par .WordCount() laga ke result le sakte ho — reusability aur readability dono badh gayi! 💪 🧩 3️⃣ Null-Conditional Assignment (1:25 – 1:50) ...

JDBC Operation to Create, Read , Update and Delete record using MYSQL Database server with JSP and Servlet




How we view student record in JSP:-
ViewStudent.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
          <a href="StudentInfo.jsp">BACK</a>
          <br>
          <hr>
          <h6>VIEW STUDENT RECORD HERE</h6>
          <hr>
          <table border="1" width="800" >
              <tr><th>RNO</th><th>NAME</th><th>BRANCH</th><th>FEES</th><th>OPERATION</th></tr>
        <%
          Class.forName("com.mysql.jdbc.Driver");
          Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stuinfo","root","");
          Statement st = con.createStatement(); 
          ResultSet res = st.executeQuery("select * from student");
          while(res.next())
          {  %>
              <tr><td><%= res.getInt(1)    %> </td><td><%= res.getString(2)    %></td><td><%= res.getString(3)    %></td><td><%= res.getString(4)    %></td>
           
                  <td><a href="EditStudent.jsp?q=<%= res.getInt(1)    %>"><img src="delete.png" width="30" height="30" /></a> <a href="Deletestudent.jsp?q=<%= res.getInt(1)    %>"><img src="edit.png" width="30" height="30"></a></td>
              </tr>
                   <%}
                 %>
              </table>
       </body>
</html>
EditStudent.jsp
<%-- 
    Document   : EditStudent
    Created on : Mar 11, 2020, 6:02:44 PM
    Author     : Hp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Are You Sure to Update Record</h1>
        <hr>
        <%
         Class.forName("com.mysql.jdbc.Driver");
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stuinfo","root","");
         Statement st = con.createStatement();
         ResultSet res = st.executeQuery("select * from student where rno='"+request.getParameter("q") +"'");
         if(res.next())
         {       
                        
         %>
         <form action="UpdateSer"  method="post">
             
             <table>
                 <tr><td>RNO</td><td><input type="text" name="txtrno" value="<%= res.getInt(1) %>"</td></tr>
                 <tr><td>Name</td><td><input type="text" name="txtname" value="<%= res.getString(2) %>"</td></tr>
                 <tr><td>Branch</td><td><input type="text" name="txtbranch" value="<%= res.getString(3) %>"</td></tr>
                 <tr><td>Fees</td><td><input type="text" name="txtfees" value="<%= res.getString(4) %>"</td></tr>
                 <tr><td colspan="2"><input type="submit" name="btnsubmit" value="Update" %></td></tr>
             </table>
               <%
         }
         %>
             
         </form>
    </body>
</html>
UpdateSer
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 *
 * @author Hp
 */
public class UpdateSer extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            PrintWriter out = response.getWriter();
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stuinfo","root","");
            Statement st = con.createStatement();
            int x = st.executeUpdate("update student set name='"+request.getParameter("txtname")+"',branch='"+request.getParameter("txtbranch")+"',fees='"+request.getParameter("txtfees")+"' where rno='"+request.getParameter("txtrno")+"'");
            if(x!=0)
            {
              response.sendRedirect("viewstudent.jsp");
            }
            
        } catch (Exception ex) {
          
        }
    }
}
DeleteStudent
<%-- 
    Document   : EditStudent
    Created on : Mar 11, 2020, 6:02:44 PM
    Author     : Hp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
         Class.forName("com.mysql.jdbc.Driver");
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stuinfo","root","");
         Statement st = con.createStatement();
         ResultSet res = st.executeQuery("select * from student where rno='"+request.getParameter("q") +"'");
         if(res.next())
         {                      
            
         %>
         <form action="DeleteSer"  method="post">
             <h1> Are You Sure to delete record</h1>
             <hr>
                 
             <table>
                 <tr><td>RNO</td><td><input type="hidden" name="txtrno" value="<%= res.getInt(1) %>" /><%= res.getInt(1) %></td></tr>
                 <tr><td>Name</td><td><%= res.getString(2) %></td></tr>
                 <tr><td>Branch</td><td><%= res.getString(3) %></td></tr>
                 <tr><td>Fees</td><td><%= res.getString(4) %></td></tr>
                 <tr><td colspan="2"><input type="submit" name="btnsubmit" value="Delete" %></td></tr>
             </table>
             
                 <%
         }
         %>
             
         </form>
    </body>
</html>
DeleteSer
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 *
 * @author Hp
 */
public class DeleteSer extends HttpServlet {
     protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            PrintWriter out = response.getWriter();
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stuinfo","root","");
            Statement st = con.createStatement();
            int x = st.executeUpdate("delete from student  where rno='"+request.getParameter("txtrno")+"'");
            if(x!=0)
            {
              response.sendRedirect("viewstudent.jsp");
            }
            
        } catch (Exception ex) {
          
        }
    }
}



Comments

Popular posts from this blog

Conditional Statement in Python

It is used to solve condition-based problems using if and else block-level statement. it provides a separate block for  if statement, else statement, and elif statement . elif statement is similar to elseif statement of C, C++ and Java languages. Type of Conditional Statement:- 1) Simple if:- We can write a single if statement also in python, it will execute when the condition is true. for example, One real-world problem is here?? we want to display the salary of employees when the salary will be above 10000 otherwise not displayed. Syntax:- if(condition):    statements The solution to the above problem sal = int(input("Enter salary")) if sal>10000:     print("Salary is "+str(sal)) Q)  WAP to increase the salary of employees from 500 if entered salary will be less than 10000 otherwise the same salaries will be displayed. Solution:- x = int(input("enter salary")) if x<10000:     x=x+500 print(x)   Q) WAP to display th...

DSA in C# | Data Structure and Algorithm using C#

  DSA in C# |  Data Structure and Algorithm using C#: Lecture 1: Introduction to Data Structures and Algorithms (1 Hour) 1.1 What are Data Structures? Data Structures are ways to store and organize data so it can be used efficiently. Think of data structures as containers that hold data in a specific format. Types of Data Structures: Primitive Data Structures : These are basic structures built into the language. Example: int , float , char , bool in C#. Example : csharp int age = 25;  // 'age' stores an integer value. bool isStudent = true;  // 'isStudent' stores a boolean value. Non-Primitive Data Structures : These are more complex and are built using primitive types. They are divided into: Linear : Arrays, Lists, Queues, Stacks (data is arranged in a sequence). Non-Linear : Trees, Graphs (data is connected in more complex ways). Example : // Array is a simple linear data structure int[] number...

Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025

 Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025 Now a days most of the IT Company asked NODE JS Question mostly in interview. I am creating this article to provide help to all MERN Stack developer , who is in doubt that which type of question can be asked in MERN Stack  then they can learn from this article. I am Shiva Gautam,  I have 15 Years of experience in Multiple IT Technology, I am Founder of Shiva Concept Solution Best Programming Institute with 100% Job placement guarantee. for more information visit  Shiva Concept Solution 1. What is the MERN Stack? Answer : MERN Stack is a full-stack JavaScript framework using MongoDB (database), Express.js (backend framework), React (frontend library), and Node.js (server runtime). It’s popular for building fast, scalable web apps with one language—JavaScript. 2. What is MongoDB, and why use it in MERN? Answer : MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. It...