ORA-17041: Missing IN or OUT parameter at index:

    You forgot to register the out parameter using the registerOutParameter.
    eg:
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Types;
    
    import oracle.jdbc.OracleDriver;
    
    public class Test17041 {
    	public static void main(String[] args) {
    		try {
    			new OracleDriver();
    			Connection conn = DriverManager.getConnection(
                                 "jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger");
    			CallableStatement stat = conn.prepareCall("{ call ? := test_17041(?) }");
    			//stat.registerOutParameter(1, Types.NUMERIC);
    			stat.setInt(2, 42);
    			stat.execute();
    			System.out.println(stat.getInt(1));
    		} catch(SQLException e) {
    			System.err.println("Error: " + e.getErrorCode());
    			e.printStackTrace();
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
    
    Solution: add a call to the registerOutParameter.

    Alternatively, there is a problem with the Oracle 10g JDBC driver when trying to use the :NEW or :OLD Oracle keywords in a PreparedStatement.

    This will happen if you try to create a trigger using PrepareStatement instead of the Statement.
    eg:
        final Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@"+cs, user, pw );
    
        String sql = "create or replace trigger t_bir before insert on t for each row ";
        sql += "begin :new.c := :new.c+1; end;";
        PreparedStatement pstmt; 
    
        pstmt = conn.prepareStatement(sql);  
        pstmt.execute();
        pstmt.close();
    
    Previous example fails with a ORA-17041 when using the Oracle 10g JDBC driver because we reference the :NEW keyword inside the PrepareStatement call.
    If we change the example to use Statement instead, we solve the problem:
        Statement pstmt; 
    
        pstmt = conn.createStatement();  
        pstmt.executeQuery(sql);
        pstmt.close();
    
    Creating triggers using the Oracle Enterprise Manager are know to have this problem.

    Solution: Either use a different version of the JDBC driver or change the code so it's using the Statement call.

    Here's another style that worked in 9i but fails in 10g with an (inappropriate) ORA-17041 error:
    String sql = "BEGIN" +
                 "    insert into FOO (ID,VALUE) values 1001,'Something' RETURNING ID into :1;" +
                 "    update BAR set FOO_ID = :1 where ID = 20002;";
    CallableStatement stat = conn.prepareCall(sql); stat.registerOutParameter(1, Types.NUMERIC); stat.execute();
    LOG.info("Result: " + stat.getLong(1));
    
    With the Oracle-style bind parameters, you can now use each bind variable only once.


Adverteren bij Daisycon
Forum Messages
06-FEB-2008 02:23:20not able to get i am created a procedure with 18 parameters in which 6 are in 1 is inout and rest of them are out parametersvamsikrishna Reply

org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call requestCardDetails(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; SQL state [null]; error code [17041]; Missing IN or OUT parameter at index:: 20; nested exception is java.sql.SQLException: Missing IN or OUT parameter at index:: 20
Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 20
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1813)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3279)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3389)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4222)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:877)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:842)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:875)
at org.springframework.jdbc.object.StoredProcedure.execute(StoredProcedure.java:113)
at com.btcom.test.RequestCardDetailsDaoImpl$MyStoredProcedure.execute(RequestCardDetailsDaoImpl.java:134)
at com.btcom.test.RequestCardDetailsDaoImpl.showCardDetails(RequestCardDetailsDaoImpl.java:33)
at com.btcom.test.TestDAO.main(TestDAO.java:15)
06-FEB-2008 02:36:42Value of registerOutParameter(20, Types.NUMERIC);DbMotive Reply
What is the value of registerOutParameter(20, Types.NUMERIC) set to?
06-FEB-2008 10:21:34hi again i am getting the same Reply
we are using spring dao +jdbcdaosupport i dont exactly where i have to look to slove this problem
Add your message for ORA-17041
Name:email:
Validation Code:qe7ukw3ewa5fxq8ny
Enter Code above:
Title:
State your problem: