Adobe 38040334 - Dreamweaver CS3 User Manual page 660

Pc
Hide thumbs Also See for 38040334 - Dreamweaver CS3:
Table of Contents

Advertisement

Dreamweaver inserts ASP code in your page that, when run on the server, creates a command that inserts, updates,
or deletes records in the database.
By default, the code sets the Prepared property of the Command object to
reuse a single compiled version of the object every time the command is run. To change this setting, switch to Code
view and change the Prepared property to
Create a page with an HTML form so users can enter record data. In the HTML form, include three text fields
7
(txtCity, txtAddress, and txtPhone) and a submit button. The form uses the
values to the page that contains your command.
About JSP prepared statements
A JSP prepared statement is a reusable server object that contains a SQL statement. You can place any valid SQL
statement in a prepared statement. For example, a prepared statement can contain a SQL statement that returns a
recordset, or one that inserts, updates, or deletes records in a database.
A prepared statement is reusable in the sense that the application server uses a single instance of the prepared
statement object to query the database a number of times. Unlike the JSP statement object, a new instance of the
prepared statement object is not created for each new database query. If you know the statement will be executed
more than a few times, having a single instance of the object can make database operations more efficient and take
up less server memory.
A prepared statement object is created by a Java scriptlet on a JSP page. However, Dreamweaver lets you create
prepared statements without writing a single line of Java code.
If you're interested in the code, the following scriptlet creates a prepared statement:
String myquery = "SELECT * FROM EMPLOYEES WHERE DEPARTMENT = ?";
PreparedStatement mystatement = connection.prepareStatement(myquery);
The first line stores the SQL statement in a string variable called
holder for the SQL variable value. The second line creates a prepared statement object called
Next, you assign a value to the SQL variable, as follows:
mystatement.setString(1, request.getParameter("myURLparam"));
The
method assigns the value to the variable and takes two arguments. The first argument specifies the
setString
affected variable by its position (here, the first position in the SQL statement). The second argument specifies the
variable's value. In this example, the value is provided by a URL parameter passed to the page.
Note: You must use different methods to assign non-string values to SQL variables. For example, to assign an integer to
the variable, you would use the
Finally, you generate the recordset, as follows:
ResultSet myresults = mystatement.execute();
Use JSP prepared statements to modify a database
You can use Dreamweaver to create JSP prepared statements that insert, update, or delete records in a database. A
JSP prepared statement is a reusable server object that contains a SQL statement. You supply the prepared statement
with the SQL that performs the operation on the database.
In Dreamweaver, open the JSP page that will run the command.
1
.
false
method.
mystatement.setInt()
September 4, 2007
, which makes the application server
true
method and submits the text field
GET
, with a question mark serving as a place-
myquery
mystatement
DREAMWEAVER CS3
653
User Guide
.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Dreamweaver cs3

Table of Contents