我有这个代码片段:
final String adatbazisURL = "jdbc:mysql://localhost:3306";
Connection kapcsolat = null;
Statement utasitas = null;
try {
Class.forName("com.mysql.jdbc.Driver");
kapcsolat = DriverManager.getConnection(adatbazisURL, felhNev,
jelszo);
utasitas = kapcsolat.createStatement();
String sql = "USE"+Azonositok.getAdatbazisNev()+";";
utasitas.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
String sql = "DROP PROCEDURE IF EXISTS proba ;";
utasitas.executeUpdate(sql);
sql = "CREATE PROCEDURE proba (" + "IN number1 INTEGER, "
+ "OUT number2 INTEGER) " + "BEGIN " +
"SET number2 = number1;" + "END";
utasitas.execute(sql);
CallableStatement callableStatement = null;
String callString = "{CALL proba(?,?)}";
callableStatement = kapcsolat.prepareCall(callString);
callableStatement.setInt(1, 5);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.execute();
int number = callableStatement.getInt(2);
callableStatement.close();
当我运行此代码时,它会抛出“参数号 2 不是 OUT 参数”异常。为什么?