/**
call a function in the database
a function is essentially a stored procedure that returns a result, and this example demonstrates how to invoke a function with the in, out, and in/out arguments
***********************************/
CallableStatement cs;
try {
//Call a function with no parameters; function returns a VARCHAR
//Preprocessing callable statement
cs = Connection.preparecall ("{? = Call MyFunc} ");
//Registration return value type
Cs.registeroutparameter (1, i);
//Execute and retrieve the returned value
Cs.execute ();
String RetValue = cs.getstring (1);
//Call function with an in parameter; The function returns a VARCHAR
cs = Connection.preparecall ("{? = Call Myfuncin (?)} ");
//Register The type of the return value
cs.registeroutparameter (1, Types.varchar);
Set the value for the in parameter
cs.setstring (2, "a string");
//Execute and retrieve the returned value
Cs.execute ();
RetValue = cs.getstring (1);
//Call function with an out parameter; The function returns a VARCHAR
cs = Connection.preparecall ("{? = Call Myfuncout (?)} ");
//Register The types of the return value and out parameter
cs.registeroutparameter (1, Types.varchar);
Cs.registeroutparameter (2, Types.varchar);
//Execute and retrieve the returned values
Cs.execute ();
RetValue = cs.getstring (1); return value
String outparam = cs.getstring (2); Out parameter
//Call function with a in/out parameter; The function returns a VARCHAR
CS = Connection.preparecall ("{? = Call Myfuncinout (?)} ");
//Register The types of the return value and out parameter
cs.registeroutparameter (1, Types.varchar);
Cs.registeroutparameter (2, Types.varchar);
//Set The value for the In/out parameter
cs.setstring (2, "a string");
//Execute and retrieve the returned values
Cs.execute ();
RetValue = cs.getstring (1); return value
Outparam = cs.getstring (2); In/out parameter
} catch (SQLException e) {
}