The callAction( ) method
// A JDBCExamples method to call a stored procedure,
// passing input and output parameters of datatype String
// and Address.
// This method illustrates callable statements, parameter markers,
// and result sets.
public static String callAction(Connection con)
throws Exception {
CallableStatement cs = con.prepareCall("{call inoutproc
(?, ?, ?, ?, ?)}");
int id = 1;
String newName = "Frank Farr";
Address newHome = new Address("123 Farr Lane", "87654");
cs.setInt(1, id);
cs.setString(2, newName);
cs.setObject(3, newHome);
cs.registerOutParameter(4, java.sql.Types.VARCHAR);
cs.registerOutParameter(5, java.sql.Types.JAVA_OBJECT);
int res = cs.executeUpdate();
String oldName = cs.getString(4);
Address oldHome = (Address)cs.getObject(5);
return "- Old values of row with id=1: name("+oldName+ )
street(" + oldHome.street + ") zip("+ oldHome.zip + );
}
}