[pro30index.jsp]
<%@ page import="java.sql.*" %>
<table align=center cellpadding=5>
<tr>
<td colspan=2 align=center><img src="logo.jpg">
<tr>
<td colspan=2 align=center><h2><i>CALLABLE STATEMENT EXAMPLE WITH PROCEDURE</i></h2>
<tr>
<td colspan=2 align=right><a href="http://master.gtu.blogspot.com">master-gtu.blogspot.com</a>
<tr>
<td align="center"><h3>BEFORE UPDATE</h3>
<jsp:include page="/pro30showtable.jsp"/>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system","system");
CallableStatement cs=con.prepareCall("{ call incrementSalary(?)}");
cs.setInt(1,10);
cs.executeUpdate();
cs.close();
con.close();
}
catch(Exception e){}
%>
<td align=center>
<h3>AFTER UPDATE</h3>
<jsp:include page="/pro30showtable.jsp"/>
</table>
[pro30showtable.jsp]
<%@ page import="java.sql.*"%>
<table border=5 align=center><tr><td>
<table cellpadding=10 align=center>
<tr bgcolor="pink">
<th>Empid<th>Emp Name<th>Designation<th>Joining Date<th>Salary
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
PreparedStatement ps;
String q="";
Boolean flag=false;
String ch=request.getParameter("ch");
String val=request.getParameter(ch);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from employee");
while(rs.next())
{
%>
<tr><td><%=rs.getInt(1)%>
<td><%=rs.getString(2)%>
<td><%=rs.getString(3)%>
<td><%=rs.getString(4)%>
<td><%=rs.getInt(5)%>
<%
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
out.println(e);
}
%>
</table>
</table>
for creating procedure copy following to oracle dos prompt:
ReplyDeleteCREATE OR REPLACE PROCEDURE incrementSalary(per IN number)
IS
val number;
BEGIN
update employee set emp_salary=emp_salary+(per*emp_salary/100);
END
can you explain me with simple example..
ReplyDeleteSay, you got a nice article post.Really thank you! Really Great.
ReplyDeletedot net online course
. net online training