STORED PROCEDURES in JSP

Can you give me some sample code in using a certain SP on my JSP?
a simple one is preferred. thx!

I have called this SPs to display the message from my MAILBOX and this is my code:
String strSQL = "EXECUTE spGetNewMessage @IDMsg = 12345";
rs = stmt.executeQuery(strSQL); //where IDMsg in my DB is = 12345
the message in DB withIDMsg 12345 is displayed calling this SP using JSON: (im using JSON for this module)
String strSQLx = "EXECUTE spGetOneMsgWRecipient @IDMsg=" + IDMsgJSON;
rsx = stmtx.executeQuery(strSQLx);
while (rsx.next())
String body = rsx.getString("strBody"); // the message body is here
main.put("Message:", body);
rsx.close();
i need your help if i want to display a certain msg. under certain category. i also have SP for my categories.
how will i display the message for each category in my mailbox?
pls. help.
thank you.

Similar Messages

  • HOW TO CALL STORED PROCEDURES IN JSP

    CAN ANY ONE SEND A SAMPLE CODE , HOW A STORED PROCEDURE CAN BE CALLED IN JSP
    THANKS
    SPUTNIK

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by any:
    Oreilly jdbc and java explain well.
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection(url, "scott", "tiger");
    CallableStatement cs = con.prepareCall("EXECUTE storedprocedurename(?,?)");
    cs.setInt(1, cid);
    cs.registerOutParameter(2, java.sql.Types.VARCHAR);
    ResultSet rs = cs.executeQuery();
    while (rs.next())
    { %>
    <tr>
    <td> <%= rs.getString(2) %> </td> //<%= rs.getString("country_name") %>
    </tr><HR></BLOCKQUOTE>
    Hi ,i am not very sure whether the call execute in the prepare call statement works please try for CALL in the following way:
    con.prepareCall("{call storedProcedurename(?,?)}");

  • Calling stored procedure from JSP

    I call a stored procedure from a JSP, but I want to show a page which tells the user that the query is busy executing (it's a big one!) while the stored procedure is executing. I have a page where I select an option, which forwards the request to the JSP that calls the stored procedure. When the procedure has finished, it must forward to a page that tells the user that the procedure executed successfully. The problem I have is that when I select the desired option and click Submit, the next JSP (which should tell the user that the query is executing) doesn't load until after the stored procedure is finished. How can I display this page while the stored procedure is executing?

    The problem I have is that when I select the desired
    option and click Submit, the next JSP (which should
    tell the user that the query is executing) doesn't
    load until after the stored procedure is finished. How
    can I display this page while the stored procedure is
    executing?
    HAve you got the call to the bit that displays the HTML before or after the call to the stored procedure? If it is before then it should display it...not sure if this is the best solution but if you have a .jsp page that first does the html telling the user to wait and then call the procedure should work...

  • Run PL/SQL stored procedure under JSP

    Quick question: how do I run a Stored Procedure built on PL/SQL from my JSP program.
    I'm using JDEV 9i, and Oracle 9i.
    Thanks.

    REPOST Again, please, don't let me die.!.

  • Calling PL/SQL stored procedure from JSP tag

    Hello,
    I need to call a PL/SQL procedure from a JSP tag , I donot want to use any Bean to call the PL/SQL procedure. How would I call PL/SQL stored procedure from within JSP using JSP tag library, need some code.
    Thank you
    Syed

    need to call a PL/SQL procedure from a JSP tag , I donot want to use any Bean to call the PL/SQL procedure. How would I call PL/SQL stored procedure from within JSP using JSP tag library, need some code.
    regards
    Indira Rani Bandi

  • Running a SQL Server Stored Procedure in JSP

    Hi peoples!
    I have a whole heaps of stored procedure sitting in a SQL Server database I need to make use of.
    Im not sure of the code I need to use to access them, and display information from them.
    Thanks a heap

    You Need to set up a connection object like thus:
    Connection conn1 = DriverManager.getConnection("jdbc:odbc:NameOfDatabase", "UserName", "Password");
    and then call the following:
    CallableStatement cs = conn1.prepareCall("{call spHowMyTeamPerforms(?, ?)}");
    cs.setString(1, TeamId);
    cs.setInt(2, viewId);
    ResultSet result2 = cs.executeQuery();
    As you can see I have a stored procedure called spHowMyTeamPerforms which expects two parameters, which explains the bumpf underneath.
    Look through the tutorials about PreparedStatements and Callable statements as well

  • Java, Stored Procedure/Function,  JSP

    Hello All,
    Is there any one who can help.
    I would like to return a record set from a stored function and display the results with a JSP program.
    The same function is currently being used to retrieve data for a related process, but that process uses a procedure to call the function and the results are written to a database table. This works fine.
    This time I would like to create a record set and display the results on screen, but I am having problems.
    ResultSet rsTimecard = null;
    Connection conn = sqlMgr.getConnection();
    CallableStatement cs = conn.prepareCall("{ ? = call TA_WEBDBA_HOURS_USE_PKG.aftimecard_jocas_records(to_date('01-OCT-2004', 'DD-MON-YYYY'), to_date('30-OCT-2004', 'DD-MON-YYYY')) }");
    cs.registerOutParameter(1, Types.OTHER); // This is line 99. Types.OTHER is the Invalid column type that the system is complaining about.
    cs.execute();
    rsTimecard = (ResultSet) cs.getObject(1);
    <table width="100%">
    <%
    while(rsTimecard.next())
    %>
    <tr>
    <td colspan="1" width="10%"> 
    </td>
    <td colspan="1" width="10%">
    <%=rsTimecard.getString(1)%>
    </td>
    I get:
    Application Error
    The following error occurred: Invalid column type
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:189)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:231)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:294)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:5992)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterBytes(OracleCallableStatement.java:250)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:389)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:446)
    at com.evermind.sql.FilterCallableStatement.registerOutParameter(FilterCallableStatement.java:373)
    at aftimecard.jsp._PSRptView._jspService(PSRptView.jsp:99)
    at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:139)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:349)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:778)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
    at java.lang.Thread.run(Thread.java:534)

    Rufus,
    Have you seen the Refcursor Sample? I believe it will help you.
    http://tinyurl.com/5r6hm
    Good Luck,
    Avi.

  • Using Stored Procedure in JSP

    Hi Everybody,
    I hope some one can help me out. I want to call a PL/SQL Procedure in my JSP Page. Can anybody please tell me how this can be done.
    Thanks

    hi,
    here i am sending some code jsp page with sqlserver.
    i hope you can learn from this
    <%@ page import="java.sql.*" %>
    <html>
    <body bgcolor="lightblue">
    <%
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:test1","sa","password");
    CallableStatement cs = con.prepareCall("{call jp_test1}");
    ResultSet rs = cs.executeQuery();
    while(rs.next())
    out.println(rs.getString(1)+"<br>");
    }catch(Exception e1)
    %>
    </body>
    </html>
    <%--
    my procedure in sql server 200 look like this
    CREATE PROCEDURE dbo.jp_proc1
    As
    Select BALANCE balance from accounts
    GO
    --%>
    with regards
    jp reddy

  • How to call stored procedure from postgresql to jsp

    i'm using a jdeveloper.. and i'm a newbie of jsp.. i just wanna know how to call a stored procedure in jsp?... This is my function in postgres and i don't know how to call it in jsp...
    SELECT * from SP_1('2006-01-11') as ( company_code char(5), branch_category char(5), branch_code char(15), day_sales numeric(19,2), month_to_date numeric(19,2), no_of_transaction int8, month_to_date_py numeric(19,2), year_to_date numeric(19,2), year_to_date_py numeric(19,2), remarks text, time_reported text );

    hi again.. i'm using jsp in jdeveloper, i just wanna know how to declare double in jsp because my module is report and i need to get the average daily sales = 4500/ no. of transaction = 3. This is my code.. Where will i put the code in declaring the double and the average daily sales? Thanks in advance..
    <%@ page contentType="text/html;charset=windows-1252" import="java.sql.*,Connect.CRMCon"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
    </head>
    <body>
    <%
    String ave = request.getParameter("ave_daily_sales");
    double cashsales = Double.parseDouble(ave);
    %>
    <%
    logparameters data = new logparameters();
    data.txtbox = request.getParameter("txtbox");
    %>
    <table cellspacing="3" cellpadding="2" border="1" width="100%">
    <tr>
    <td width="5%" bgcolor="#cccccc" height="29">
    <DIV align="center">Company Code</DIV>
    </td>
    <td width="4%" bgcolor="#cccccc" height="29">
    <DIV align="center">Branch Category</DIV>
    </td>
    <td width="6%" bgcolor="#cccccc" height="29">
    <DIV align="center">Branch Code</DIV>
    </td>
    <td width="8%" bgcolor="#cccccc" height="29">
    <DIV align="center">Day Sales</DIV>
    </td>
    <td width="9%" bgcolor="#cccccc" height="29">
    <DIV align="center">Month to Date</DIV>
    </td>
    <td width="5%" bgcolor="#cccccc" height="29">
    <DIV align="center">No.of Transaction</DIV>
    </td>
    <td width="9%" bgcolor="#cccccc" height="29">
    <DIV align="center">Month to Date(PY)</DIV>
    </td>
    <td width="9%" bgcolor="#cccccc" height="29">
    <DIV align="center">Ave.Daily Sales to Date</DIV>
    </td>
    <td width="9%" bgcolor="#cccccc" height="29">
    <DIV align="center">Year to Date</DIV>
    </td>
    <td width="9%" bgcolor="#cccccc" height="29">
    <DIV align="center">Year to Date(PY)</DIV>
    </td>
    <td width="9%" bgcolor="#cccccc" height="29">
    <DIV align="center">Remarks</DIV>
    </td>
    <td width="5%" bgcolor="#cccccc" height="29">
    <DIV align="center">Time Reported</DIV>
    </td>
    </tr>
    <%
    try
    CRMCon ccon = new CRMCon();
    Connection con = ccon.getConnection();
    String sql = "select * from sp_1('"+data.txtbox+"')";
    // String sql = "SELECT * from SP_1('"+ request.getParameter("data.txtbox")+"')" ;
    sql += " as (company_code char(5), branch_category char(5) ," ;
    sql += "branch_code char(15) , day_sales numeric(19,2)," ;
    sql += "month_to_date numeric(19,2), no_of_transaction int8," ;
    sql += "month_to_date_py numeric(19,2), year_to_date numeric(19,2)," ;
    sql += "year_to_date_py numeric(19,2), remarks text, time_reported text) " ;
    //out.println(sql);
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery(sql);
    while (rs.next())
    %>
    <tr>
    <td width="13%"> <%= rs.getString("company_code") %> </td>
    <td width="63%"> <%= rs.getString("branch_category") %> </td>
    <td width="24%"> <%= rs.getString("branch_code") %> </td>
    <td width="24%"> <%= rs.getString("day_sales") %> </td>
    <td width="24%"> <%= rs.getString("month_to_date") %> </td>
    <td width="24%"> <%= rs.getString("no_of_transaction") %> </td>
    <td width="24%"> <%= rs.getString("month_to_date_py") %> </td>
    <td width="24%"> <%= rs.getString("year_to_date") %> </td>
    <td width="24%"> <%= rs.getString("year_to_date_py") %> </td>
    <td width="24%"> <%= rs.getString("remarks") %> </td>
    <td width="24%"> <%= rs.getString("time_reported") %> </td>
    </tr>
    <%
    catch (Exception ex)
    out.println("Error:"+ex.getMessage());
    %>
    </table>
    </body>
    </html>
    <%!
    class logparameters
    public String txtbox;
    %>

  • Help in calling stored procedure with parameter in JSP

    I need to know how to call this stored procedure in JSP
    here is my Stored procedure in oracle 9i:
    CREATE OR REPLACE procedure broker_activity
    (p_broker_id IN number,p_TotalValue out number,p_CrossValue out number, p_blockValue out number, p_MktWeight out number,p_BuyingVal out number, p_sellingVal out number, p_NetValue out number)
    AS
    begin
    declare
    -- buying value
    cursor c_BuyingVal is select buyer_firm, sum(volume*price) value from last_sale where buyer_firm = p_broker_id group by buyer_firm;
    -- selling value
    cursor c_SellingVal is select seller_firm,sum(volume*price) value from last_sale where seller_firm = p_broker_id group by seller_firm;
    v_BuyingCurVal c_buyingVal%rowtype;
    v_SellingCurVal c_sellingVal%rowtype;
    n_buy_val number :=0;
    n_sell_val number :=0;
    n_total_value number := 0;
    begin
    --buying value
    open c_BuyingVal;
    fetch c_BuyingVal into v_buyingCurVal;
    n_buy_val := nvl(n_buy_val,0) + v_buyingCurVal.value;
    --Exit when c_BuyingVal%NOTFOUND;
    close c_buyingVal;
    p_BuyingVal := n_buy_val;
    --selling value
    open c_SellingVal;
    fetch c_SellingVal into v_SellingCurVal;
    n_sell_val := nvl(n_sell_val,0) + v_SellingCurVal.value;
    -- Exit when c_BuyingFirm%NOTFOUND;
    close c_SellingVal;
    p_SellingVal := n_sell_val;
    --total value
    p_TotalValue := n_buy_val + n_sell_val;
    --cross val
    select sum(volume*price) into p_CrossValue from last_sale where board = 'C' and (buyer_firm = p_broker_id or seller_firm = p_broker_id);
    --block Sale
    select sum(volume*price) into p_BlockValue from last_sale where board = 'B' and (buyer_firm = p_broker_id or seller_firm = p_broker_id);
    --Net Value
    p_NetValue := n_buy_val - n_sell_val;
    --markte_weight
    select (sum(volume*price) * 2)/100 into p_MktWeight from last_sale ;
    end;
    end;

    http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html

  • Pass a date parameter to Stored Procedure

    Hello friends,
    Can you help to pass a date parameter to Stored procedure from JSP. This is my code:
    In Oracle 9i I have this:
    PROCEDURE SP_EDORES(
    pfechaini IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    pfechafin IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    p_recordset OUT PKG_REP_CIERRE.cursor_type) AS
    In JSP have this:
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setDate(1,Date.valueOf("01-06-2005"));
    stmt.setDate(2,Date.valueOf("30-06-2005"));
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    <TR>
    <TD ALIGN=CENTER> <%= rset.getString(1) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(2) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(3) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getInt(4) %> </TD>
    </TR>
    <%
    The Stored Procedure returns de Result set, however I think does not recognized the date format because I need it with this format dd-mm-yyyy.
    Thanks in advance

    to use Date you will need the oracle package.
    u can try this other solution: use String, not Date
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setString(1,"01-06-2005");
    stmt.setString(2,"30-06-2005");
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    if this don't work you can change your PL/SQL to get Strings and do the conversion with TO_DATE in the sql statement.

  • Performance issue on Java Stored Procedure

    I have converted the Stored Procedures into JSP with SQLJ. I
    loaded the classes (not the source) onto Oracle 8i Database and
    published within tbe stored packages. What I found out was the
    performance is about 12 times on average slower than the PL/SQL
    stored packages when I made calls to JSP. I am not surprise JSP
    is slower than PL/SQL but can we improve by tunning the Java
    codings or VM within the 8i database?
    null

    James Chan (guest) wrote:
    : I have converted the Stored Procedures into JSP with SQLJ. I
    : loaded the classes (not the source) onto Oracle 8i Database and
    : published within tbe stored packages. What I found out was the
    : performance is about 12 times on average slower than the PL/SQL
    : stored packages when I made calls to JSP. I am not surprise JSP
    : is slower than PL/SQL but can we improve by tunning the Java
    : codings or VM within the 8i database?
    all user written java code in the 8i rdbms is currently running
    as bytecode in the jvm.
    a future release will provide a component called "Native Compiler
    [NCOMP]" so it should run considerably faster then.
    see the following link for details :
    http://technet.oracle.com/files/search/search.htm?ncomp
    null

  • JSP portlet built in Jdeveloper call stored procedure

    Hi,
    I have a simple jsp portlet built with Jdeveloper, now I'm trying to execute a stored
    procedure from the jsp. How can one access database and call a proc, in a jsp which is
    developed in Jdeveloper?
    Is JSTL required for it or a normal jdbc calls will suffice?
    Any help asap is appreciated.
    Thanks,
    Kavitha

    It is actually very simple. :)
    I suggest to create a Java bean containing the Java code with the PL/SQL call.
    This method can be invoked from JSP.
    A good pratice is to pass database connection to this methode and commit or rollack in the JSP.
    example:
    public void saveData(Connection conn,
    String param1,
    String param2) throws SQLException
    With this approach you can call several SQL statements in the same session.
    This will enable transaction handling.
    I suppose the db connect will be pooled in your application.

  • How to call a stored procedure from my JSP?

    Hi to all,
              I have a very simple jsp page and a simple sql server stored procedure!
              I need to call this stored procedure by passing two parameters.
              My result set will have 4 columns.
              I would really appreciate any input on how to issue this call to a SP.
              I am new to JSP.
              Regards,
              Sam
              

              Sam,
              BEA provides examples that are shipped with the product under
              <beahome>\weblogic700\samples\server\src\examples\
              Look at the jsp directory for JSP examples that access a database and look at
              say the jdbc\oracle\storedprocs.java for an example of java code calling out to
              a stored procedure - - by combining one of the jsp database examples with this
              stored procedure example you should be 'good to go'
              Chuck Nelson
              DRE
              BEA Technical Support
              

  • Calling Oracle Stored Procedure from BC4J JSP App

    I am on an extremely tight deadline and am trying to get my JSP application to use an Oracle Stored Procedure. I need to take some input from the user and send these values as parameters. Has anyone worked with Stored Procedures in JDev3.1? Please reply with some sample code if possible.
    Thanks.

    Hi,
    Someone posted a similar request the other day. Here is my response to them:
    Basically, you need to create a custom method from your JSP's ViewObject, which calls the stored procedure. You can then call the ViewObject's custom method from the JSP client.
    Here is how I have done it:
    1. Choose the ViewObject that your JSP is based on and choose 'Edit' from the context menu.
    2. On the Java tab of the ViewObject wizard, choose Generate Java File checkbox for the View Object Class and click the Finish button. A file is created under the ViewObject node in the Navigator named 'viewobjectImpl.java'.
    3. Open the viewobjectImpl.java file in the code editor and create a method to call your stored procedure (see sample code below).
    4. Compile the VOImpl.java file.
    5. Choose the view object again, and choose Edit again from the context menu.
    6. On the Client Methods tab, you should now see your method appear in the Available field. Select it and shuttle it to the Selected field.
    7. Click Finish to leave the VO wizard, and rebuild your Business Components project.
    8. In your JSP, call the custom method (see sample code below).
    sample code for custom method calling a stored procedure from VOImpl.java file:
    public int getTotalHits(String mon, String year) {
    CallableStatement stmt = null;
    int total;
    // the call to the PL/SQL stored proc
    String totalhits = "{? = call walkthru.total_hits(?,?)}";
    // use the AM conxn 2 call storedproc
    stmt = getDBTransaction().createCallableStatement(totalhits, 1);
    try
    // Bind the Statement Parameters and //Execute this Statement
    stmt.registerOutParameter(1,Types.INTEGER);
    stmt.setString(2,mon); stmt.setString(3,year);
    stmt.execute();
    total = stmt.getInt(1);
    catch (Exception ex)
    throw new oracle.jbo.JboException(ex);
    finally
    try
    stmt.close();
    catch (Exception nex)
    return total;
    sample render code for calling custom method from JSP custom bean:
    public void render() {
    int totalhits;
    try
    Row[] rows;
    // Retrieve all records by default, the qView variable is defined in the base class
    qView.setRangeSize(-1);
    qView.first();
    rows = qView.getAllRowsInRange();
    // instantiate a view object for our exported method
    // and call the stored procedure to get the total
    ViewObject vo = qView.getViewObject();
    wtQueryView theView = (wtQueryView) vo;
    totalhits = theView.getTotalHits(session.getValue("m").toString(),session.getValue("y").toString());
    out.println(totalhits);
    } catch(Exception ex)
    throw new RuntimeException(ex.getMessage());
    }

Maybe you are looking for