Example : All Integrated JSP & Oracle 10g Code using Net Beans 8.2 [All in One Code].
<%--
Document : All Integrated Codes in JSP
Created on : 14 May, 2019, 2:15:53 PM
Author : Codershelpline
--%>
<%@include file="connect.jsp" %> // Linking of Connectivity Code file 'OR
// 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 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 UrCmbEmailSearch3=request.getParameter("UrCmbEmailSearch1");
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 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");
}
// 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");
}
// Code to Delete Data from Oracle 10g Database
if(sub2.equals("Delete"))
{
pst=conn.prepareStatement("delete from TABLENAME where UrTxtEmail5=
'"+UrTxtEmail3+"' ");
pst.executeUpdate();
out.println("Record Deleted successfully");
}
// 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">
<input type="submit" name="sub" id="subUpdate2" value="Update">
<input type="submit" name="sub" id="subDelete2" value="Delete">
</td>
</tr>
</table>
</fieldset>
</center>
</form>
</body>
</html>
Some Important links:
All Integrated Codes in Jsp
0 Comments