Results 1 to 5 of 5
  1. #1
    sasi.tati is offline Member
    Join Date
    Jul 2010
    Posts
    18
    Rep Power
    0

    Question How to call/invoke a Oracle package using java

    Hi All

    Can any one guide me how to call/invoke a oracle package using java.
    i just tried like below code which is not working properly.

    Java Code:
    cstmt = con.prepareCall("{call P_Cat_Globals()}");
    Can any one let me know how to call the package and then i have to read a variable from that package.

    Thanks in Advacne.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    "is not working properly" tells us nothing.

  3. #3
    sasi.tati is offline Member
    Join Date
    Jul 2010
    Posts
    18
    Rep Power
    0

    Default

    Hi

    I tried to call the package same as of calling a proc so it doesn't work for me, can u guide how to call a package. that's y i specified it is not working properly.

  4. #4
    juamd is offline Member
    Join Date
    Apr 2010
    Posts
    25
    Rep Power
    0

    Default Re

    Hi

    Here is an example that shows you how to call a stored procedure and print the result. The code is simple but is completely.

    Java Code:
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@localhost:1521:XE", "hr", "password");
    
    String jobquery = "begin get_emp_info(?, ?, ?); end;";
    CallableStatement callStmt = conn.prepareCall(jobquery);
    callStmt.setString(1, "param1");
    callStmt.setString(2, "param2");
    callStmt.setString(3, "param3");
    callStmt.execute();
            
    ResultSet rset = (ResultSet)callStmt.getObject(3);
    
    ResultSetMetaData rsetMeta = rset.getMetaData();
    int count = rsetMeta.getColumnCount();
    // print the results, all the columns in each row
    while (rset.next()) {
        String rsetRow = "";
        for (int i=1; i<=count; i++){
            rsetRow = rsetRow + " " + rset.getString(i);
        }
        System.out.println(rsetRow);
    }
    conn.close();
    I hope it will help you.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Quote Originally Posted by sasi.tati View Post
    Hi

    I tried to call the package same as of calling a proc so it doesn't work for me, can u guide how to call a package. that's y i specified it is not working properly.
    Errors?
    Exceptions?
    Crashes?

    What's the signature of the procedure?

    "{call <my procedure name>}" is sufficient if there are no parameters.
    "{?=call <my function>}" is sufficient for a function with only a return parameter.

Similar Threads

  1. onchange invoke java object method and submit form
    By marckamga in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-14-2010, 06:26 AM
  2. Call Oracle procedure
    By take5 in forum JDBC
    Replies: 0
    Last Post: 06-01-2010, 10:18 AM
  3. How to call Oracle stored procedure from Java?
    By parag_narkhede in forum New To Java
    Replies: 4
    Last Post: 10-07-2009, 07:50 AM
  4. How to invoke a C API using Java program
    By mgopi in forum New To Java
    Replies: 6
    Last Post: 12-27-2008, 12:17 PM
  5. Replies: 0
    Last Post: 01-02-2008, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •