/************** Call the Stored Procedure ****************/
Public static void main (string [] ARGs ){
Try {
Class. forname ("com. Microsoft. sqlserver. JDBC. sqlserverdriver ");
} Catch (classnotfoundexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Connection conn = NULL;
Callablestatement callstm = NULL;
Try {
Conn = drivermanager. getconnection (
"JDBC: sqlserver: // localhost: 1434; databasename = studb", "sa ",
"Sasa ");
// Create a stored procedure command object
Callstm = conn. preparecall ("{call proc_getstudentnamebynum (?,?)} ");//(?,?) Parameters of the stored procedure
Callstm. setint ("stunum", 123906); // assign a value to the input parameter
Callstm. registeroutparameter ("stuname", java. SQL. types. nvarchar); // you can specify the output parameter.
Callcmd.exe cuteupdate (); // executes the Stored Procedure
String result = callstm. getstring ("stuname"); // obtain the value of the output parameter
System. Out. println (result );
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Finally {
Try {
Callstm. Close ();
Conn. Close ();
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
}