30. Write a Java application to invoke a stored procedure using a CallableStatement. For this a stored procedure called incrementSalary may be developed to increase all the employees salary by a percentage specified in the parameter.
Create Procedure in Oracle
create or replace procedure incrementSalary(percent IN NUMBER)
is
BEGIN
UPDATE Employee
SET Emp_Salary = Emp_Salary + (Emp_Salary *( percent/100));
commit;
END incrementSalary;
index.jsp
<html>
<head>
<title> Ex-30 : www.BipinRupadiya.blogspot.in</title>
<LINK REL="STYLESHEET" HREF="myCss.css" TYPE="text/css">
<script>
function frmValidate(frm)
{
if(frm.txtPer.value.trim()=="")
{
alert("Enter Percentage : ");
frm.txtPer.focus();
return false;
}
if(isNaN(frm.txtPer.value))
{
alert("Invalid Percentage : ");
frm.txtPer.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<center>
<div class="abc" id="f1" align="center">
<br>
<form method="POST" action="incSal.jsp" onSubmit="return frmValidate(this)">
<table align="center">
<tr>
<td colspan=2 align=center>
<h3>Employee </h3>
<hr>
</td>
</tr>
<tr>
<td>Increment Salary by Percentage : </td>
<td><input type="text" name="txtPer" size="3" onkeypress='return isNum(event)'>%</td>
</tr>
<tr>
<td colspan=2 align=center>
<hr>
<input type="hidden" name="action" value="incSal">
<input type="submit" value="Increment Salary">
<input type="reset" value="Clear">
</td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
incSal.jsp
<%@ page import="java.sql.*" %>
<%!
String className= "oracle.jdbc.driver.OracleDriver";
String url= "jdbc:oracle:thin:@localhost:1521:xe";
String user= "scott";
String password= "tiger";
String action="x";
%>
<%
try
{
Class.forName(className);
Connection con= DriverManager.getConnection(url, user, password);
CallableStatement cs=con.prepareCall("{ call incrementSalary(?)}");
cs.setDouble(1,Double.parseDouble(request.getParameter("txtPer")));
int ans=cs.executeUpdate();
ServletContext context= getServletContext();
RequestDispatcher rd= context.getRequestDispatcher("/index.jsp");
if(ans!=0)
{
out.println("<div class=errorG>Salary Successfully updated</div>");
}
else
{
out.println("<div class=errorR>Problem in update</div>");
}
rd.include(request, response);
cs.close();
con.close();
}
catch(Exception e)
{
out.println(""+e);
}
%>
myCss.css
.abc
{
background:#ababff;
position:absolute;
top:2in;
--height : 200px;
width:300px;
left:5in;
border-style:solid;
}
.errorG
{
background:#00Fa00;
position:absolute;
top:1in;
height:30px;
width:300px;
left:5in;
padding-top:10px;
color:#000000;
border-color:#000000;
border-style:dotted;
font-size: 13pt ;
text-align:center ;
}
.errorR
{
background:#Fa0000;
position:absolute;
top:1in;
height:30px;
width:300px;
left:5in;
padding-top:10px;
color:#000000;
border-color:#000000;
border-style:dotted;
font-size: 13pt ;
text-align:center ;
}
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment