Example : How to Save/Store Data/Record in Oracle 10g/11g database using JSP through                           Net Beans 8.2 IDE [JSP Save Code].
<%-- 
    Document   : Save Code
    Created on : 12 May, 2019, 2:55:10 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");   
%> 
<!DOCTYPE html>
//   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 UrTxtEmail3=request.getParameter("UrTxtEmail1");

    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 sub2=request.getParameter("sub"); 
    try
    {
        if(sub2!=null)
        {
            //   Code to Save Data from JSP to Oracle 10g
            if(sub2.equals("Submit"))
            {
                st=conn.createStatement();
                st.executeQuery("insert into TABLENAME(UrTxtUname5,UrPassPsd5,UrDateDob5,UrRdGender5,
                     UrNumMob5,UrTxtEmail5,UrChkMatric5,UrChkInter5,UrChkGrad5,UrTxrAdd5,UrCmbState5) 
                     values('"+UrTxtUname3+"','"+UrPassPsd3+"','"+UrDateDob3+"','"+UrRdGender3+"',
                     '"+UrNumMob3+"','"+UrTxtEmail3+"','"+UrChkMatric3+"','"+UrChkInter3+"',
                     '"+UrChkGrad3+"','"+UrTxrAddr3+"','"+UrCmbState3+"')");
                out.println("Data Saved Successfully");
            }        
        }
    }
    catch(Exception e)
    {
        out.println(e);        
    }    

%>
<html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Save Data 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">                                           
                        </td>
                    </tr>
                </table>
             </fieldset>
          </center>
      </form>
    </body>
</html>

Loading

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.