Stored Procedure:
-- Call myproc (?,?,?)
Alter proc myproc
(@ ID int,
@ Customerid nchar (5) output,
@ Employeeid int output
)
Begin
Select @ customerid = customerid, @ employeeid = employeeid from orders
Where orderid = @ ID
End
Go
Declare
@ Cu char (5 ),
@ Em int
Exec myproc 10248, @ Cu output, @ em output
Print (cast (@ em as char (5) + @ Cu)
The following is a Java stored procedure call:
Import java. SQL .*;
Public class study
{
Private connection con;
Public resultset re;
Private callablestatement callsta;
Private string STR;
Private string use = "sa ";
Private string Pwd = "sa ";
Public Study ()
{
Try {
// Connect to the database driver
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
String STR = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = northwind ";
Con = drivermanager. getconnection (STR, use, PWD );
// Set stored procedure parameters
String ST = "{call myproc (?,?,?)} ";
Callsta = con. preparecall (ST );
Callsta. setint (1,10248 );
Callsta. registeroutparameter (2, types. varchar );
Callsta. registeroutparameter (3, types. integer );
// Test whether the call is successful
System.out.println(callsta.exe cute ());
// Output the record results of calling the Stored Procedure cyclically
If(callsta.exe cute () = true)
{
Re = callsta. getresultset ();
While (Re. Next ())
{
System. Out. println (Re. getint (1) + "" + RE. getstring (2) + "" + RE. getint (3 ));
}
}
Else {system. Out. println ("dfas ");}
}
Catch (exception e) {e. printstacktrace ();}
}
Public static void main (string [] age)
{
Study study = new study ();
}
}