beautypg.com

Run a stored procedure (asp), Run a stored procedure (jsp) – Adobe Dreamweaver CS3 User Manual

Page 664

background image

DREAMWEAVER CS3

User Guide

657

See also

“Define an advanced recordset by writing SQL” on page 550

Run a stored procedure (ASP)

With ASP pages, you must add a command object to a page to run a stored procedure. For more information on
command objects, see “About ASP command objects” on page 651.

1

In Dreamweaver, open the page that will run the stored procedure.

2

In the Bindings panel (Window > Bindings), click the Plus (+) button, and then select Command (Stored

Procedure).

The Command dialog box appears.

3

Enter a name for the command, select a connection to the database containing the stored procedure, and then

select Stored Procedure from the Type pop-up menu.

4

Select your stored procedure by expanding the Stored Procedures branch in the Database Items box, selecting the

stored procedure from the list, and clicking the Procedure button.

5

Enter any required parameters in the Variables table.

You don’t need to enter any parameters for any

RETURN_VALUE

variable.

6

Click OK.

After you close the dialog box, ASP code is inserted in your page. When the code runs on the server, the code creates
a command object that runs a stored procedure in the database. The stored procedure in turn performs a database
operation, such as inserting a record.

By default, the code sets the Prepared property of the Command object to

true

, which makes the application server

reuse a single compiled version of the object every time the stored procedure is run. If you know the command will
be executed more than a few times, having a single compiled version of the object can improve the efficiency of
database operations. However, if the command will only be executed one or two times, using one might actually slow
down your web application because the system has to pause to compile the command. To change the setting, switch
to Code view and change the Prepared property to

false

.

Note: Not all database providers support prepared commands. If your database does not support it, you might get an
error message when you run the page. Switch to Code view and change the Prepared property to

false

.

If the stored procedure takes parameters, you might create a page that gathers the parameter values and submits them
to the page with the stored procedure. For example, you may create a page that uses URL parameters or an HTML
form to gather parameter values from users.

Run a stored procedure (JSP)

With JSP pages, you must add a Callable server behavior to a page to run a stored procedure.

1

In Dreamweaver, open the page that will run the stored procedure.

2

In the Bindings panel (Window > Bindings), click the Plus (+) button and select Callable (Stored Procedure).

3

In the Callable (Stored Procedure) dialog box, enter a name for the stored procedure.

4

In the Connections pop-up menu, select a connection to the database containing the stored procedure.

5

In the Database Items box, expand the Stored Procedures branch, select the stored procedure from the list, and

click the Procedure button.

September 4, 2007