1. Call a stored procedure without Parameters
Use JDBC driverProgramWhen calling a stored procedure without parameters, you must use the call SQL escape sequence. The syntax for the call escape sequence without parameters is as follows:
{Call procedure-name}
As an instance, create the following stored procedure in the SQL Server 2005 adventureworks sample database:
SQL code
Create procedure getcontactformalnames
As
Begin
Select top 10 Title + ''+ firstname +'' + lastname as formalname
From person. Contact
End
This stored procedure returns a single result set containing a column of data (composed of the names, names, and surnames of the first 10 contacts in the person. Contact table ).
In the following example, this function will be passed to the open connection of the adventureworks sample database, and then the executequery method will be used to call the getcontactformalnames stored procedure.
JAVA codepublic static void executesprocnoparams (connection con) {
try {
statement stmt = con. createstatement ();
resultset rs = stmt.exe cutequery (" {call DBO. getcontactformalnames} ");
while (RS. next () {
system. Out. println (Rs. getstring (" formalname ");
}< BR style =" line-Height: normal! Important; ">
Rs. Close ();
stmt. Close ();
}catch (exception e) {
E. printstacktrace ();
}< BR style =" line-Height: normal! Important; ">
}
Transferred from:Http://www.cn-java.com/www1? Action-viewnews-itemid-55626