simogeek
simogeek

Reputation: 21

java.sql.SQLException: Paramètre IN ou OUT absent dans l'index :: 3

I am new to Oracle and was trying to call my procedure from a package via callStat but the following error:

java.sql.SQLException: Paramètre IN ou OUT absent dans l'index :: 3

I read many posts about this issue but cannot really localize my porblem, any clue?

Here is my procedure:

PROCEDURE get_employees(
     emp_no IN  number,   
     batch_size  IN     NUMBER,   
     found       IN OUT NUMBER, 
     done_fetch  OUT    NUMBER, 
     emp_name    OUT    name,
     emp_dept    OUT    dept,
     emp_salary  OUT    sal) IS



BEGIN
       IF NOT get_emp%ISOPEN THEN      -- open the cursor if
           OPEN get_emp(emp_no);  -- not already open
       END IF;
   done_fetch := 0;  -- set the done flag FALSE
   found := 0;

   FOR i IN 1..batch_size LOOP
       FETCH get_emp INTO emp_name(i), emp_dept(i), emp_salary(i);
       IF get_emp%NOTFOUND THEN    -- if no row was found
           CLOSE get_emp;
           done_fetch := 1;   -- indicate all done
           EXIT;
       ELSE
           found := found + 1;  -- count row
       END IF;
   END LOOP;


END;

and a part of the java code

public class main1 {

public static void main(String[] args) {

    Connection conn = null;
    CallableStatement cst = null;
    ResultSet rs = null;
    int emp_no = 100;
    Object temp;

    try {
        Class.forName ("oracle.jdbc.OracleDriver");

        conn =DriverManager.getConnection("yada yada yada");
        conn.setAutoCommit(false);
        System.out.println("Successfuly connected!");


            cst = conn.prepareCall("{ call get_employees.pkg1(?,?,?,?) }");
                cst.setInt(1, emp_no);
                cst.registerOutParameter(2, OracleTypes.CURSOR);
                cst.execute();
                rs = (ResultSet) cst.getObject(2);
                ResultSetMetaData rsm = rs.getMetaData();
                int columnCount = rsm.getColumnCount();
                while (rs.next()){
                    for (int j=0;j< columnCount;j++){
                        temp = rs.getObject(j+1);
                    }
                }

Upvotes: 0

Views: 7352

Answers (1)

nilsman
nilsman

Reputation: 396

You hadn't set parameters #3 and #4. Also you call registerOutParameter for IN parameter #2.

Upvotes: 1

Related Questions