Interacting with Databases
Executing SQL Statements
14
Executing SQL Statements
To execute SQL statements, first create a
statement
object by invoking the
connection
object’s
newStatement
method. The newly created
statement
object
can be used to access any row or column within the database table and execute SQL
commands.
In the following example, a
statement
object is created for the
Q32000Data
database
created in the previous sections:
myStatement = myConnection.newStatement();
The
statement
object provides the methods shown below in
Table 14.2:
T
ABLE
14.2
Statement Object
Method
Description
Executes an SQL statement
Obtains a column within the table
Obtains an array of columns within the table
Obtains the current row in the table
Iterates to the next row in the table
execute
getColumn
getColumnArray
getRow
nextRow
In addition to the methods shown above in
Table 14.2,
the
statement
object provides
two useful properties:
columnCount
: the number of columns in each row of results returned by a query
●
rowCount
: the number of rows affected by an update
To execute an SQL statement, invoke the
statement
object’s
execute
method, which
●
accepts a string parameter containing the SQL statement. Note that any names containing
spaces must be surrounded by escaped quotation marks, as shown in the following
example:
// Create the SQL statement:
var SQLStatement = ‘Select * from \"Client Data\"’;
// Execute the SQL statement:
myStatement.execute(SQLStatement);
Acrobat JavaScript Scripting Guide
241