0

I want to call the Oracle Sql functions using java. But I am getting error

java.sql.SQLException: Missing IN or OUT parameter at index:: 4

Can any body please help me regarding this?

Below are the statments for reading Oracle SQL Function.

DECLARE
  ID VARCHAR2(10);
  date1 DATE;
  output PL/SQL RECORD;
BEGIN
 ID := '1234';
  date1  := to_date('2018-05-15','yyyy-MM-dd');
  output := Function1(
    ID   => I_EMPL_ID,
    date1  => I_BALANCE_DATE
  );
END;

Here below is the code I used in java for calling function:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy");

 Date now = new java.sql.Date(simpleDateFormat.parse("17-MAY-18").getTime());

 CallableStatement cstmt = con.prepareCall("{? = call Function1(?,?,?)}");

               cstmt.setString(1, "1234");
               cstmt.setDate(2, now);
               cstmt.registerOutParameter(3, Types.ROWID);
               cstmt.execute();

When I execute this code, I am getting the below error:

java.sql.SQLException: Missing IN or OUT parameter at index:: 4

Can anybody help me regarding this?

1
  • 1
    You are supposed to provide a value for the fourth ? . Commented May 18, 2018 at 7:57

1 Answer 1

1
CallableStatement cstmt = con.prepareCall("{? = call Function1(?,?,?)}");

Has 4 ? bind parameters.

                                            ^                  ^ ^ ^
                                            1                  2 3 4

The first is the return value from the function and the second, third and fourth are the arguments to the function.

cstmt.registerOutParameter( 1, Types.ROWID );
cstmt.setString( 2, "1234" );
cstmt.setDate(   3, now );
cstmt.setInteger(4, 0 );       // Or whatever type the 3rd function argument has.
cstmt.execute();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.