Search This Blog

Sunday, 16 September 2012

Practical 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.


Filename-MyCallProcedure.java

package deff30;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.sql.*;

public class MyCallProcedure  extends HttpServlet
{
                   public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
                   {
                             res.setContentType("text/html");
                                      PrintWriter out=res.getWriter();
                             try
                             {
                                      Class.forName("oracle.jdbc.OracleDriver");

                                      String url="192.168.1.1:1521:password";
                                      String username="uername";
                                      String password="password";

                                      Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@"+url,username,password);

                                      String myprocedure="{ call incsal(?)}";

                                      CallableStatement cs=conn.prepareCall(myprocedure);
                                      //cs.registerOutParameter(1,Types.INTEGER);
                                      cs.setFloat(1,10);
                                      cs.execute();
                                      //int totalmark=cs.getInt(1);
                                      //if(myans)
                                      out.println("Update successfully");
                                      conn.close();
                             }

                             catch(Exception e)
                             {
                                      out.println(e);
                             }

                   }

                   public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
                   {
                             doGet(req,res);
                   }
}

No comments:

Post a Comment