Example : How to  Edit/Modify/Change/Update data or record in Oracle 10g/11g using  jsp [JSP Edit/Update Code].

<%-- 
    Document   : JSP Update Code
    Created on : 14 May, 2019, 2:15:53 PM
    Author     : Codershelpline
--%>

//   JSP & Oracle 10g Connectivity Code
<%@page contentType="text/html; charset=utf-8" language="java" import="java.sql.*"import=
       "java.util.*" errorPage=""%>
<%
    Connection conn=null;
    PreparedStatement pst=null;
    ResultSet rs;
    Statement st=null;
	
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","putusernamehere",
         "putpasswordhere");
    out.println("Database connected");

//   Code for Transfer Html data into JSP variables   
    String UrTxtUname3=request.getParameter("UrTxtUname1");
    String UrPassPsd3=request.getParameter("UrPassPsd1");
    String UrDateDob3=request.getParameter("UrDateDob1");    
    String UrNumMob3=request.getParameter("UrNumMob1");    

    String UrRdGender3=request.getParameter("UrRdbGender1");
    String UrChkMatric3=request.getParameter("UrChkMatric1");
    String UrChkInter3=request.getParameter("UrChkInter1");
    String UrChkGrad3=request.getParameter("UrChkGrad1");

    String UrTxrAddr3=request.getParameter("UrTxrAddr1");
    String UrCmbState3=request.getParameter("UrCmbState1");
	
    String UrTxtEmail3=request.getParameter("UrTxtEmail1");  
    String sub2=request.getParameter("sub");

    try
    {
        if(sub2!=null)
        {
//   Code to Edit/Modify/Update Database Data via JSP			
	    if(sub2.equals("Update"))
	    {
		pst=conn.prepareStatement("update TABLENAME set UrTxtUname5='"+UrTxtUname3+"', 
                UrPassPsd5='"+UrPassPsd3+"',UrDateDob5='"+UrDateDob3+"',UrRdGender5='"+UrRdGender3+"'
                ,UrNumMob5='"+UrNumMob3+"',UrChkMatric5='"+UrChkMatric3+"',UrChkInter5=
                '"+UrChkInter3+"',UrChkGrad5='"+UrChkGrad3+"',UrTxrAdd5='"+UrTxrAddr3+"',
                UrCmbState5='"+UrCmbState3+"' where UrTxtEmail5='"+UrTxtEmail3+"'");
		pst.executeUpdate();
		out.println("Data Updated Successfully");
	    }		
	  }            
      }    
    catch(Exception e)
    {
        out.println(e);        
    }
%>
<!DOCTYPE html>
<html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>All Integrated Code</title>
    </head>

    <body>   
        <form><center>
            <fieldset style="width: 60%; background-color: aliceblue; border-radius: 8px; border- 
                     width: 4px; border-color: cadetblue">                
                <table>
                   <h1>User Registration Page</h1>
                   <hr style="width: 90%">
                
                    <tr>
                        <td>User Name</td>
                        <td>:</td>
                        <td>
                            <input type="text" name="UrTxtUname1" id="UrTxtUname2" placeholder="Enter 
                                 User ID">
                        </td>                       
                      </tr>

                      <tr>
                         <td>Password</td>
                         <td>:</td>
                         <td>
                            <input type="password" name="UrPassPsd1" id="UrPassPsd2" 
                                 placeholder="Enter Password">
                         </td>
                       </tr>
                    
                    <tr>
                        <td>Date of Birth</td>
                        <td>:</td>
                        <td>
                            <input type="date" name="UrDateDob1" id="UrDateDob2">
                        </td>
                    </tr>

                    <tr>
                        <td>Gender</td>
                        <td>: </td>
                        <td>
                            <input type="radio" name="UrRdbGender1" id="UrRdbGenderM2" value="Male" 
                                 >Male 
                            <input type="radio" name="UrRdbGender1" id="UrRdbGenderF2" value="Female" 
                                 >Female 
                        </td>
                    </tr>
                    
                    <tr>
                        <td>Mobile No.</td>
                        <td>:</td>
                        <td>
                            <input type="number" name="UrNumMob1" id="UrNumMob2" placeholder="Enter 
                                 10 digit No.">
                        </td>
                    </tr>

                    <tr>
                        <td>E-mail</td>
                        <td>:</td>
                        <td>
                            <input type="Email" name="UrTxtEmail1" id="UrTxtEmail2" 
                                 placeholder="[email protected]">
                        </td>
                    </tr>

                    <tr>
                        <td>Qualification Details</td>
                        <td>:</td>
                        <td>
                            <input type="checkbox" name="UrChkMatric1" id="UrChkMatric2" 
                                  value="Matric">Matric
                            <input type="checkbox" name="UrChkInter1" id="UrChkInter2" 
                                  value="Intermediate">Intermediate
                            <input type="checkbox" name="UrChkGrad1" id="UrChkGrad2" 
                                  value="Graduation">Graduation
                        </td>
                    </tr>
                    
                    <tr>
                        <td>Address</td>
                        <td>:</td>
                        <td>
                            <textarea rows=10 cols=15 name="UrTxrAddr1" id="UrTxrAdd2"> 
                                    </textarea>
                        </td>
                    </tr>

                    <tr>
                        <td>State</td>
                        <td>:</td>
                        <td>
                            <select name="UrCmbState1" id="UrCmbState2">
                                <option value="Select One">Select One</option>
                                <option value="Bihar">Bihar</option>
                                <option value="Uttar Pradesh">Uttar Pradesh</option>
                            </select>
                        </td>
                    </tr>
                    
                    <tr>
                        <td></td>
                        <td></td>
                        <td>
                            <input type="submit" name="sub" id="subSubmit2" value="Submit">
                            <input type="reset" name="sub" id="subReset2" value="Reset">
                            <input type="submit" name="sub" id="subUpdate2" value="Update">                                           
                        </td>
                    </tr>
                </table>
             </fieldset>
          </center>
      </form>
    </body>
</html>

 1,810 total views,  1 views today

Categories: JSP

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.