Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    4

    Post Unanswered: How to call a function with JDBC in DB2 v8.1?

    Hi All,

    I am a newbie. I am using DB2, I want to call a SQL user-define function with JDBC. I don't know how to call a SQL function? Please help.

    ----------------
    --SQL function
    --------- ------
    CREATE FUNCTION ADMINISTRATOR.TEST2( )
    RETURNS INTEGER
    SPECIFIC ADMINISTRATOR.MYFUNC1
    BEGIN ATOMIC
    RETURN SELECT count(*) FROM SYSCAT.FUNCTIONS;
    END

    //
    // javac code
    //

    Connection con = connectSQL(); // connection to DB2
    String execRPC = "{call ADMINISTRATOR.TEST2}";
    CallableStatement scs = con.prepareCall(execRPC);
    scs.execute();

    The error message is:

    COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0444N
    ................
    reason code: "4". SQLSTATE=42724
    at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(UnknownSource)
    at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(UnknownSource)
    at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_r eturn_code(Unknownource)
    at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2 (UnknownSource)
    at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute( UnknownSource)

    How to call the SQL function ? Pls help.

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    I will give you a hint. The way you would call it in SQL is like:

    SELECT ADMINISTRATOR.TEST2( ) from sysibm.sysdummy1

    Andy

  3. #3
    Join Date
    Sep 2004
    Posts
    4
    Hi Andy,

    Thank you very much.

    regards,
    pan_21cn

Posting Permissions

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