public static void Main (string[] args)
{
Connection Conn =getconnection (URL,USER,PWD);
SYSTEM.OUT.PRINTLN ("Data connection succeeded");
CallableStatement Cs=null;
Try
{//Call a stored procedure in the database
CS =conn.preparecall ("{Callpro_deleteproducttype (?,?)}"); /pro_deleteproducttype is the name of the stored procedure to invoke, the first parameter is the shaping input parameter, the second parameter is the output parameter
Set input parameters for a stored procedure
Cs.setint (1, 24);
Sets the stored procedure return value type and executes
Cs.registeroutparameter (2,java.sql.types.varchar);
Cs.execute ();
Receives the return value and prints
String str = cs.getstring (2);
System.out.println (str); Calling database functions
CS1 = Conn.preparecall ("{? =call fun_str ()}"); //Where fun_str () is the function name,? is a placeholder for the return value Cs1.registeroutparameter (1,java.sql.types.varchar); Cs1.execute (); Stringstring1=cs1.getstring (1); SYSTEM.OUT.PRINTLN ("The result of the function call is:" +string1);
}
catch (SQLException e)
{
TODO auto-generated Catch block
E.printstacktrace ();
}
Finally
{//Close all connections
CloseAll (conn, CS, null);
}
}
Calling stored procedures and functions in the database in Java