Detailed description of stored procedures for calling SQL Server using Java-stored procedures without Parameters

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.