Regarding execution of pl/sql procedure using JSP

HI all
Please help me.
i am customizing a jsp page ,which is executing one sql procedure first then selecting data from the table in which procedure is inserting.
How can i pass parameter dynamically to the sql procedure ? ,which i am getting from an HTML page.
Please help me out.
regards
satendra

this is the sample code provided by oracle.
* This sample shows how to call PL/SQL blocks from JDBC.
import java.sql.*;
class PLSQL
public static void main (String args [])
throws SQLException, ClassNotFoundException
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String url = "jdbc:oracle:oci8:@";
try {
String url1 = System.getProperty("JDBC_URL");
if (url1 != null)
url = url1;
} catch (Exception e) {
// If there is any security exception, ignore it
// and use the default
// Connect to the database
Connection conn =
DriverManager.getConnection (url, "scott", "tiger");
// Create the stored procedures
init (conn);
// Cleanup the plsqltest database
Statement stmt = conn.createStatement ();
stmt.execute ("delete from plsqltest");
// Close the statement
stmt.close();
// Call a procedure with no parameters
CallableStatement procnone = conn.prepareCall ("begin procnone; end;");
procnone.execute ();
dumpTestTable (conn);
procnone.close();
// Call a procedure with an IN parameter
CallableStatement procin = conn.prepareCall ("begin procin (?); end;");
procin.setString (1, "testing");
procin.execute ();
dumpTestTable (conn);
procin.close();
// Call a procedure with an OUT parameter
CallableStatement procout = conn.prepareCall ("begin procout (?); end;");
procout.registerOutParameter (1, Types.CHAR);
procout.execute ();
System.out.println ("Out argument is: " + procout.getString (1));
procout.close();
// Call a procedure with an IN/OUT prameter
CallableStatement procinout = conn.prepareCall ("begin procinout (?); end;");
procinout.registerOutParameter (1, Types.VARCHAR);
procinout.setString (1, "testing");
procinout.execute ();
dumpTestTable (conn);
System.out.println ("Out argument is: " + procinout.getString (1));
procinout.close();
// Call a function with no parameters
CallableStatement funcnone = conn.prepareCall ("begin ? := funcnone; end;");
funcnone.registerOutParameter (1, Types.CHAR);
funcnone.execute ();
System.out.println ("Return value is: " + funcnone.getString (1));
funcnone.close();
// Call a function with an IN parameter
CallableStatement funcin = conn.prepareCall ("begin ? := funcin (?); end;");
funcin.registerOutParameter (1, Types.CHAR);
funcin.setString (2, "testing");
funcin.execute ();
System.out.println ("Return value is: " + funcin.getString (1));
funcin.close();
// Call a function with an OUT parameter
CallableStatement funcout = conn.prepareCall ("begin ? := funcout (?); end;");
funcout.registerOutParameter (1, Types.CHAR);
funcout.registerOutParameter (2, Types.CHAR);
funcout.execute ();
System.out.println ("Return value is: " + funcout.getString (1));
System.out.println ("Out argument is: " + funcout.getString (2));
funcout.close();
// Close the connection
conn.close();
// Utility function to dump the contents of the PLSQLTEST table and
// clear it
static void dumpTestTable (Connection conn)
throws SQLException
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select * from plsqltest");
while (rset.next ())
System.out.println (rset.getString (1));
stmt.execute ("delete from plsqltest");
rset.close();
stmt.close();
// Utility function to create the stored procedures
static void init (Connection conn)
throws SQLException
Statement stmt = conn.createStatement ();
try { stmt.execute ("drop table plsqltest"); } catch (SQLException e) { }
stmt.execute ("create table plsqltest (x char(20))");
stmt.execute ("create or replace procedure procnone is begin insert into plsqltest values ('testing'); end;");
stmt.execute ("create or replace procedure procin (y char) is begin insert into plsqltest values (y); end;");
stmt.execute ("create or replace procedure procout (y out char) is begin y := 'tested'; end;");
stmt.execute ("create or replace procedure procinout (y in out varchar) is begin insert into plsqltest values (y); y := 'tested'; end;");
stmt.execute ("create or replace function funcnone return char is begin return 'tested'; end;");
stmt.execute ("create or replace function funcin (y char) return char is begin return y || y; end;");
stmt.execute ("create or replace function funcout (y out char) return char is begin y := 'tested'; return 'returned'; end;");
stmt.close();
}

Similar Messages

  • Invoking PL/SQL procedure from JSP

    Hi
    Is there any solution, to invoke a PL/SQL procedure from JSP?

    my example: PL/SQL procedure named: getsidforwinuser and the following in a JSP file
    <%
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@hostname:port:SID", "User", "Password");
    CallableStatement FindID = conn.prepareCall("{ ? = call getsidforwinuser ( ? )}");
    FindID.registerOutParameter (1, Types.INTEGER);
    FindID.setString (2, DomainIntern.trim()+"\\"+Username);
    UserID = ((OracleCallableStatement)FindID).getInt(1);
    conn.close();
    catch(SQLException e)
    throw new RuntimeException("SQL Exception " + e.getMessage());
    %>
    <h1>User ID is:<%= UserID %></h1>

  • Calling pl/sql procedure from jsp

    Hi:
    Could anyone tell me how to call a pl/sql procedure from a jsp page by passing args or without . Is there any specific method to use.
    Thanks.

    Like from any other java code
    <%
    Connection conn = DriverManager.getConnection(...);
    CallableStatement cs = conn.prepareCall("BEGIN myprocedure(); END;");
    cs.execute();
    %>
    With params:
    <%
    Connection conn = DriverManager.getConnection(...);
    CallableStatement cs = conn.prepareCall("BEGIN myprocedure(?, ?); END;");
    cs.setInt(1, 10);
    cs.setString(2,"aaaa");
    cs.execute();
    %>
    to return some value as out param
    Connection conn = DriverManager.getConnection(...);
    CallableStatement cs = conn.prepareCall("BEGIN myprocedure(?, ?, 3); END;");
    cs.setInt(1, 10);
    cs.setString(2,"aaaa");
    cs.registerOutParameter(3, Types.VARCHAR);
    cs.execute();
    out.println("Returned value: " + cs.getString(3));
    %>
    Of course after all close statement and connection to free resources.

  • Link to PL/SQL procedure using a Template Manager template.

    Hi,
    I need to link a portal application report (report from SQL query) to a SQL procedure that uses a template manager template. The PL/SQL procedure requires parameters. I'm not be able to create a link based on a PL/SQL procedure. The only solution I found is to setup a link to a Form based on that procedure. But the form is only used to call the PL/SQL procedure by clicking the submit button and redirect to the template.
    Another question:
    Is it planed to support dynamic links based on column conditions?
    I'm using Portal release 3.0.7.6.2.
    thanks in advance
    Jens

    Jens,
    You may want to search the Oracle9iAS Portal Applications forum. It may have the answer you are looking for. This forum is for questions related to the Portal Development Kit.
    Thanks,
    Sue
    Sue

  • Retrieve image from my sql database using jsp

    I want to retrieve image from my sql (blob type) & save it in given relative path in server .(using jsp and servlets)
    please give me some sample codes.

    PreparedStatement pst = null;
      ResultSet rs=null;
    pst = conn.prepareStatement("select image from imagedetails where imageid='"+imageid+"'");
    rs=pst.executeQuery();
    while(rs.next())
                                byte[] b=rs.getBytes("image");
                                FileOutputStream fos=new FileOutputStream("c://image.jpg");
                                fos.write(b);
                            } hi this the code to retrieve the image from DB and write to a file.

  • Sql*loader using JSP

    wht is the way of using sqlldr in JSP script to load data Oracle DB from a csv file.
    i know how we do sqlldr in cmd.
    can we provide the sqlldr command to system by using jsp if yes how?

    SQL*Loader is a command-line utility. In theory, since Java can call out to the operating system, you could invoke SQL*Loader on the application server to load data into Oracle. It would probably be more appropriate, though, to copy the CSV to the database server and make use of an external table in the database to do the load.
    Justin

  • PL/SQL Procedures using TIME

    hello all,
    i need some help with using time in my table. how do i insert a time (what data type do i use, and what does the INSERT statement look like), eg. i want a time like 1:00:00am, 2:00:00pm in my receiveTime column.
    i have a table:
    ID receiveTime
    1 need a time
    2 need a time
    3 need a time
    THEN, how would i write a condition for this procedure, the condition is that i want to compare my System Time with the Time in the receiveTime column.
    eg. if system time > receive time THEN blah blah;
    Edited by: kwerty on Nov 7, 2008 11:47 PM
    Edited by: kwerty on Nov 8, 2008 1:18 AM
    editted my post a little

    DECLARE
        t TIMESTAMP := TIMESTAMP '2008-11-08 11:00:00';
    BEGIN
        DBMS_OUTPUT.PUT_LINE('t:             ' || t);
        DBMS_OUTPUT.PUT_LINE('time now:      ' || SYSTIMESTAMP);
        DBMS_OUTPUT.PUT_LINE('30 mins ago:   ' || (SYSTIMESTAMP - INTERVAL '30' MINUTE));
        DBMS_OUTPUT.NEW_LINE;
        IF t < SYSTIMESTAMP - INTERVAL '30' MINUTE
        THEN
            DBMS_OUTPUT.PUT_LINE('Time t is in the last 30 minutes');
        ELSE
            DBMS_OUTPUT.PUT_LINE('t is 30 minutes ago or earlier');
        END IF;
    END;
    t:             08-NOV-08 11.00.00.000000
    time now:      08-NOV-08 11.33.49.010000000 +00:00
    30 mins ago:   08-NOV-08 11.03.49.010000000 +00:00
    Time t is in the last 30 minutes
    PL/SQL procedure successfully completed.

  • Parallel execution of PL/SQL procedures

    Hi All,
    I want to execute two PL/SQL procedures in parallel. Basically I want to execute one procedure in background and other procedure in foreground from a piece of PL/SQL code. How can I do that. Any help?

    See DBMS_JOB.
    Richard

  • How to connect to MS SQL server using JSP?

    Hi, i am new to JSP so i would like to know what is the code to create a connection to MS SQL server.
    I am using jakarta-tomcat 4 as my server.
    sorry for any inconvenient....
    pls help me....

    This works to start off with but there are more sophisticated/ different ways of doing things,for instance it's best not to access the db via your jsp, rather do this logic in JavaBeans, Servlets or use Struts.Therefore, it's best that you consult with others and find out which is best way to go about creating your web apps.
    Here's some code:
    In my jsp's I access the bean below , instantiate a statement object and go on from there:
    *SOME of the code in the JSP's.
    //create bean instance
    <jsp:useBean id='dbConn' class='projectsevenhouses.DatabaseConnectionBean ' scope='session' />
    //instantiate statement
    Statement st = dbConn.getConnection().createStatement();
    * JavaBean
    package projectsevenhouses;
    public class DatabaseConnectionBean implements Serializable {   
    private Connection conn;
    private Statement st;
    private String dbURL = "jdbc:odbc:datasource";
    private static String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    /** Creates a new instance of DatabaseConnectionBean */
    public DatabaseConnectionBean() {
    makeConnection();
    public void setDatabaseName(String dbName) {
    dbURL = dbName;
    private void makeConnection() {
    try {
    Class.forName(driver);
    conn = DriverManager.getConnection(dbURL,"sa","");
    } catch (SQLException e) {
    System.out.println("SQL Cause ->" + e.toString());
    } catch (ClassNotFoundException cnf) {
    System.out.println("Class Not Found:" + cnf);
    public Connection getConnection() {
    if (conn == null) {
    makeConnection();
    return conn;
    public void setCloseConnection(boolean close) {
    if (close) {
    try {
    conn.close();
    } catch (Exception e) {
    conn = null;
    Hope it gives u an idea...
    Ciao
    Ushanta

  • Regarding Locking of PL/SQl Procedure or function

    Hi,
    My PL/SQL code is getting locked. The flow is like this.
    My PL/SQL code writes a particular data into a file which is read by a C program. Once the processing is done then the C driver writes back into anither file called response file from which my PL/SQL code reads from. What is happening is I use dbms_lock.sleep in my PL/SQL code. Now my PL/SQL code is hanging. In the sense when try to recompile my PL/SQL file, it gets timed out saying that It could not lock the object [Function Name]. How can I find out whether any other process is using my File or not. Even if it using how can I release the lock.
    Thanks in avance

    I think you have executed this PL/SQL code earlier and is hung. When you are trying to recompile that, it is not allowing to change the code as it is already being used and "locked".
    You need to find out the session which is holding the lock on this code and kill the same.

  • Query regarding connecting dashboards with SQL DATABASE using WSDT

    Hello Sir,
    I am trying to connect dashboards with Sql database via WSDT, but i have encountered the same problem as described in your SAP community blog (SAP Web Service Design Tool: From web service creation to Xcelsius consumption).
    when i tried connecting CR server with WSDT ,it still shows that total number of available licenses is 0.
    What can be done to solve this issue.
    for your detail reference, we are using CRS NUL version's 60 days Evaluation keys and same with Xcelsius Departmental edition.
    I would really appreciate, if you revert back to my mail as soon as possible

    Which version of Crystal Reports are you using? The regular ReportDocument SDK probably isn't robust enough to handle this, unless you create a connection using that connection string at design-time which you don't change at runtime. You might be able to add those properties using the in-proc RAS SDK, though. This is available with CRXI R2 as of SP2, and CR2008.

  • Regarding hierarchy creation from sql tables using db / ud connect

    bw version 3.0 upgrading to 7.0
    sql version 2005.
    we had built a sql data mart which is being accesses by a number of reporting tools. BI is one of the systems connected to it. My requirement is to upload hierarchies like customer from the sql data mart in to BW.
    The sql tables are in a denormalized format like this,
    EMPLOYEE_ID LAST_NAME                 MANAGER_ID      LEVEL
            101 Kochhar                          100                             1
            108 Greenberg                        101                            2
            109 Faviet                           108                                3
    They say that all third party reporting tools will recognize the above format and it universal. <b>I wanted to know is there any setting in bw that will allow extraction of hierarchies from the above table format ? if not I can only think of arranging data in the format of BW transfer structure, similar to flat file load.</b>
    I want to know can I upload hierarchies from sql tables or should I create flat files from tables ?
    Inputs will be awarded points.
    Message was edited by:
            aravind sam

    generate datasource? see if this can help..
    RSA1-> SOURCE SYSTEM-> SELECT YOUR SOURCE SYSTEM-> RIGHT CLICK-> GENERATE SOURCE SYSTEM.
    Also check:
    DB connect ORACLE - table name not found
    Re: Bw With ORacle
    Datasource in DB Connect
    and OSS Notes: 518241
    assign points if useful ***
    Thanks,
    Raj

  • Calling pl/sql procedure from a java class.

    I have an onSubmit event that needs to call a pl/sql procedure using the named connection. Can anyone tell me how this is code in a Model 1 ADF JSP page?

    Look at the following related thread:
    Programatically setting attribute values.

  • PL/SQL procedure -- log files?

    Say when i execute a PL/SQL procedure using SQL* Plus. Is there a place where these executions are stored/logged? Any trace files?
    And, when a Java program calls my stored procedure, is there a place these transactions are stored, just to check what exactly is being passed to my stored procedure and what the procedure gave back as result set?
    Any pointers will be appreciated. Thanks.

    Hi
    Use a system.out.println(parametername) to check what values you are passing to the procedure.. you can see the results in your application server console.
    Thanks

  • Calling PL\SQL procedures

    What's the best way to invoke a PL\SQL procedure using Java?
    I am hoping to use the values passed from the JSP into the database for computations but don't know how to call the procedure after the commit.
    Any ideas?
    Thanks a lot!

    Example follows for a PL/SQL proc call from a Java application that returns a result set and displays it in a scrolling pane. Hope it helps you:
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try
    CallableStatement call =
    OpenDBConnections.myJdbcConnection.prepareCall
    ("{? = call MY_PLSQL_PROC(?)}");
    call.registerOutParameter(1,OracleTypes.CURSOR);
    call.setString(2,partNumber_tf.getText().toString());
    call.execute();
    OracleResultSet rset=(OracleResultSet)call.getObject(1);
    /* use caching result set cuz it is non scrollable stored proc result */
    model = new CachingResultSetTableModel(rset);
    result_tbl = new JTable(model);
    status_tf.setText(result_tbl.getRowCount()+" matching Rows found.");
    jScrollPane1.getViewport().add(result_tbl, null);
    rset.close();
    call.close();
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    catch (SQLException esql)
    System.out.println(esql.toString());
    }

Maybe you are looking for

  • Mirror iMac via ethernet questions

    I want to play iTunes [ very few iTunes store songs], and movie/tv shows, [none purchased from iTunes] I added the origin of media because I heard it made difference [?] I have an ethernet connection availabe for the Apple TV. What problems can anyon

  • I deactivated my account in May but I was charged again.. What is going on?

    Hi, my number is currently deactivated because I am overseas for the moment (I believe the date of deactivation was sometime around mid-May). A couple of days ago, I received an e-mail saying my balance is past due. From what I recall, since my deact

  • Row Calculation Line Height Issue: Not Same Height as Column Lines

    Hi, I am using BI 4.1 SP4 with Microsoft SQL Server 2012. When building calculations, I have noticed that the height of the line (in the rows section) is not the same as the line in the columns section. It is slightly larger. By the third calculation

  • Count the occurences of a specific combination of chars

    Hi there I want to count the occurences of a specific combination of characteristic in a query. Example count the occurences of combination CHAR1 CHAR2 CHAR3 CHAR1 CHAR2 CHAR3 Counter A     BB     CCC    1 A     BB     CCC    1 A     BB     DDD    1

  • Multiple Mail Windows open in 10.6.4?

    After upgrading to 10.6.4, when I click any "mail" icon (alias or application), it always opens multiple windows (3 to be exact) of mail. There's no reason for me to ever need to do this. Here's a link to the screenshot to show you: http://www.216bra