这是我的存储过程。
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();
}
很抱歉,我想添加了堆栈跟踪。这里是。感谢
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)
在这种情况下它的参数1但是我可以移动parms并以不同的顺序获得错误。