Call pl/sql function from Java
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Call pl/sql function from Java

Hybrid View

  1. #1
    Join Date
    Jun 2000
    Location
    Bethel CT, USA
    Posts
    18
    How do you call a stored-function (oracle 8i) from Java code?

    Exaple: I wrote sf_Days(...) function which returns a number.

    How does a Java-code program call my function?


  2. #2
    Join Date
    Feb 2000
    Location
    New York,U.S.A.
    Posts
    245
    You could fine some samples in $ORACLE_HOME/jdbc/demo/samples.

  3. #3
    Join Date
    Jun 2000
    Location
    Bethel CT, USA
    Posts
    18
    This is what the developer is trying to use (NO SUCCESS)
    ...why?:

    CallableStatement cs = db.getConnection().prepareCall("{call SF_DAYS(?,?,?)}");
    cs.setString(1,"US");
    cs.setDate(2,new Date(2000,9,9));
    cs.setString(3,"B");
    // cs.registerOutParameter(4, java.sql.Types.INTEGER);
    cs.execute();
    int nDays = 0;
    cs.getInt(nDays);

    My function is:

    create or replace function sf_days(CountryCode varchar2,ProcessDate date,Daystype varchar2)
    return number

    ...


    Thanks

  4. #4
    Join Date
    Sep 2000
    Posts
    305

    call function from oracle in java

    CallableStatement cstmt = conn.prepareCall("{? = CALL balance}");
    cstmt.registerOutParameter(1,Type.FLOAT);
    cstmt.setInt(2,acctno);
    cstmt.executeUpdate();
    float acctBal = cstmt.getFloat(1);


    OR

    u can directly execute query
    for e.g
    ur function name is fun_checkaccess and u r passing one parameter
    u can write query like this

    select fun_checkaccess(inputparameter) from dual;

Posting Permissions

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


Click Here to Expand Forum to Full Width