Example : How to Search & assign a specific data/record from oracle 10g /11g into html                            elements of a page. [JSP Search Code].

<%-- 
    Document   : JSP Search Code
    Created on : 14 May, 2019, 1:28:17 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");

    String UrTxtEmail3=request.getParameter("UrTxtEmail1");  
    String sub2=request.getParameter("sub");
	
//  JSP Variable declaration Code
    String UrTxtUname4="";
    String UrPassPsd4="";
    String UrDateDob4="";    
    String UrNumMob4="";
    String UrTxtEmail4="";
	
    String UrRdbGender4="";
    String UrChkMatric4="";   
    String UrChkInter4="";    
    String UrChkGrad4="";
    
    String UrTxrAddr4="";
    String UrCmbState4="";	

    String Gender1="";
    String Gender2="";	
    String Check1="";
    String Check2="";
    String Check3="";

    try
    {
        if(sub2!=null)
        {
//   Code to Search Unique Record from Oracle 10g Database and Fill into HTML box			
            if (sub2.equals("Search"))
	    {
		pst=conn.prepareStatement("select * from TABLENAME where 
                     UrTxtEmail5='"+UrCmbEmailSearch3+"'");
		rs=pst.executeQuery();				
		while(rs.next())
		{
		UrTxtUname4=rs.getString("UrTxtUname5");
		UrPassPsd4=rs.getString("UrPassPsd5");
		UrDateDob4=rs.getString("UrDateDob5");
		UrNumMob4=rs.getString("UrNumMob5");
		UrTxtEmail4=rs.getString("UrTxtEmail5");
					
		UrRdbGender4=rs.getString("UrRdbGender5").trim();
		        if(UrRdbGender4.equals("Male"))
			{
			   Gender1="checked";
			}
			if(UrRdbGender4.equals("Female"))
			{
			   Gender2="checked";
			}
					
		UrChkMatric4=rs.getString("UrChkMatric5").trim();
			if(UrChkMatric4.equals("Matric"))
			{
			   Check1="checked";
			}
		UrChkInter4=rs.getString("UrChkInter5").trim();
			if(UrChkInter4.equals("Intermediate"))
			{
			   Check2="checked";
			}
		UrChkGrad4=rs.getString("UrChkInter5").trim();
			if(UrChkGrad4.equals("Graduation"))
			{
			   Check3="checked";
			}
					
		UrTxrAddr4=rs.getString("UrTxrAdd5");
		UrCmbState4=rs.getString("UrCmbState5");					
		}
	    }            
        }
    }
    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>        
        <script>
		
//    Code for Auto Combo Selection on Matching Oracle 10g Database Data
            function comboautoselect()
            {
                var x="<%=UrCmbState4%>"    //   Code to Transfer JSP Data into Java Script           
                document.getElementById("UrCmbState2").value=x;  //Code to Assign Java Script Value 
                                                                   into HTML Box
            }
        </script>
    </head>

    <body onload="comboautoselect()">    // Calling of Java Script Function on Page Load
        <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" value="<%=UrTxtUname4%>">
                        </td>
                        <td></td>
                        <td>
                           <select name="UrCmbEmailSearch1">
						   
                               // Code to Hang Oracle 10g Database Data into Combo Box
                               <option>Select One</option>
                                 <%
                                   pst=conn.prepareStatement("select UrTxtEmail5 from TABLENAME order 
                                         by UrTxtEmail5");
                                    rs=pst.executeQuery();
                                    while(rs.next())
                                    {
                                      String email6=rs.getString("UrTxtEmail5");
                                  %>
                                      <option value="<%=email6%>"><%=email6%></option>
                                  <% 
                                     }
                                   %>    
                             </select> 
							 
                             <input type="submit" name="sub" id="subSearch2" value="Search"> 
                          </td>
                      </tr>

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

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

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

                    <tr>
                        <td>Qualification Details</td>
                        <td>:</td>
                        <td>
                            <input type="checkbox" name="UrChkMatric1" id="UrChkMatric2" 
                                  value="Matric" <%=Check1%> >Matric
                            <input type="checkbox" name="UrChkInter1" id="UrChkInter2" 
                                  value="Intermediate" <%=Check2%>>Intermediate
                            <input type="checkbox" name="UrChkGrad1" id="UrChkGrad2" 
                                  value="Graduation" <%=Check3%>>Graduation
                        </td>
                    </tr>
                    
                    <tr>
                        <td>Address</td>
                        <td>:</td>
                        <td>
                            <textarea rows=10 cols=15 name="UrTxrAddr1" id="UrTxrAdd2"> 
                                    <%=UrTxrAddr4%></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.