Зачем? java.sql.SQLException: Parameter number x is not an OUT parameter

Вот моя хранимая процедура.

CREATE PROCEDURE getNumbers( out teacherCount Integer, out studentCount Integer, IN dept varchar(15))
   BEGIN

      SET teacherCount =
             (SELECT count(*)
                FROM instructor
               WHERE dept_name = dept);
      SET studentCount =
             (SELECT count(*)
                FROM student
               WHERE dept_name = dept);
   END

Вот код Java:

    CallableStatement cstmt = null;

    try {

       String SQL = "{call getNumbers(?,?,?) }";
       cstmt = conn.prepareCall (SQL);
       cstmt.registerOutParameter(1, Types.INTEGER);
       cstmt.registerOutParameter(2, Types.INTEGER);

       cstmt.setString(3, dept);


       cstmt.execute();

       int teachers = cstmt.getInt(1);
       int students = cstmt.getInt(2);

       System.out.println(teachers + " " + students);


    }
    catch (SQLException e) {
       e.printStackTrace();
    }

Sorry thought I added the stack trace. Вот. Спасибо

    java.sql.SQLException: Parameter number 1 is not an OUT parameter
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at      com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java:694)
at com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:2015)
at MyQuery.findHeadCounts(MyQuery.java:337)
at TestMyQuery.main(TestMyQuery.java:43)

Its parameter 1 in this case but I can move the parms around and get the error with a different ordering.

0 ответов

Другие вопросы по тегам