Download Using the Execute SQL Statement Operation

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Entity–attribute–value model wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Oracle Database wikipedia , lookup

Relational algebra wikipedia , lookup

Microsoft Access wikipedia , lookup

Database wikipedia , lookup

Btrieve wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Tandem Computers wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Null (SQL) wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Adobe Enterprise Technical Enablement
Using the Execute SQL Statement
Operation
In this topic, you will learn about the Execute SQL Statement operation and how it is used
to interact with databases.
Objectives
After completing this unit, you should be able to
• Use the Execute SQL Statement operation to insert data into a database
• Use the SQL Statement Info Editor dialog box to create and test SQL statements
Concepts
In this topic, you will learn about the following concepts
• Using the Execute SQL Statement operation
Copyright © 2011 Adobe Systems Incorporated
1
Using the Execute SQL Statement operation
• The Execute SQL Statement operation is used to execute a SQL statement on a database
from a process
■ Returns the number of rows that were affected
■ Typically used for SQL statements that do not return a result set, such as Insert,
Update, and Delete statements
■ Located in Foundation > JDBC - 1.0
Figure 1: Locating the Execute SQL Statement operation of the JDBC service
2
Copyright © 2011 Adobe Systems Incorporated
Setting Execute SQL Statement operation properties
• When an Execute SQL Statement operation is added to a process, the following properties
can be defined in the Properties view
■ Datasource name
– literal value or variable
– corresponds to the JNDI name configured for the data source
– formatted with a java:/ prefix
 java:/adobeTraining
■ SQL Statement
– the SQL statement to execute on the database server
– SQL Statement Info Editor is used to specify the value
■ Number of rows affected - Returned by the database - the number of rows that the
SQL statement affected
Figure 2: Execute SQL Statement properties
Copyright © 2011 Adobe Systems Incorporated
3
Using the SQL Statement Info Editor
• Use the SQL Statement Info Editor dialog box to create and test SQL statements
• Invoked by clicking the ellipsis next to the SQL Statement input property of the Execute SQL
Statement operation
• The SQL statements can include XPath expressions as well as parameter values
• Type the SQL statement in the SQL Statement box
• To use a parameter in a SQL statement, use a question mark (?) as a placeholder for the
parameter
• Click the Test button to test the SQL statement and to see the results
Figure 3: SQL Statement Info Editor
Including XPath expressions
• XPath expressions can be used to include references to process data in SQL statements
• In SQL statements, XPath expressions must appear inside braces and between dollar signs,
as in {$ XPath expression $}
• To create an XPath expression using XPath Builder, click the XPath button below the SQL
Statement box
SELECT fname FROM table1 WHERE fname LIKE '{$ /process_data/
@first_name$}%'
4
Copyright © 2011 Adobe Systems Incorporated
Including parameters
• To use parameters in SQL statements, place a question mark (?) in the SQL statement to
represent the parameters
SELECT fname FROM table1 WHERE fname LIKE ?
•
•
•
•
A parameter must be defined for each question mark placed in the statement
Use Parameterized Query must also be selected
To define a parameter, add a row to the parameter table by clicking the + button
The order in which the parameters are defined in the table is the order in which they appear
in the statement
■ Index - An index that identifies the parameter
■ Type - The type of data that the parameter holds
■ Value - The value to use for the parameter
■ Test Value - A literal value to use for the parameter when testing the statement
Copyright © 2011 Adobe Systems Incorporated
5
Task 1: Inserting data into a database
In this task, you will perform the following
• Open a process
• Configure an Execute SQL Statement operation
• Test the process
Setup
1. Create the adobetraining database.
2. Import the Execute_SQL_Statement.lca file.
Steps
Open a process
1. Login to the Workbench.
2. Open the Execute_SQL_Statement application.
3. Expand the Processes folder, right-click the ExecuteSQLStatement process and select Check
Out.
4. Double-click the ExecuteSQLStatement process to open it.
5. From the Variables view, create the following process variables.
Table 1: Process variables to create
Name
Type
Properties
empID
string
Input, Required
firstName
string
Input, Required
lastName
string
Input, Required
Configure an Execute SQL Statement operation
6. From the process diagram palette, drag the Activity Picker activity onto your process
diagram.
7. In the Define Activity dialog box, expand the Foundation category.
8. From the JDBC service, select the Execute SQL Statement operation and click OK.
9. Select the Execute SQL Statement operation and set the following properties. The XPath
Builder can be used to help construct the SQL Statement.
• Name: Insert Row in DB
• Datasource name (literal value): java:/AdobeTraining
10. Click the ellipsis button next to the SQL Statement property to open the SQL Statement Info
Editor.
6
Copyright © 2011 Adobe Systems Incorporated
11. Set the SQL Statement property.
• INSERT into employee VALUES (?,?,?)
12. Select the Use Parameterized Query option.
13. Use the editor to create the following parameters.
Table 2: Parameter values
Index
Type
Value
Test Value
1
STRING
/process_data/@empID
100
2
STRING
/process_data/@firstName
John
3
STRING
/process_data/@lastName
Jacobs
14. Click the Test button and confirm that the SQL statement executed successfully.
15. Click OK to save the changes to the SQL statement and close the SQL Statement Info Editor.
16. Save the process and Deploy the application.
Test the process
17. Right click in an empty area of the process diagram and select Invoke Process...
Copyright © 2011 Adobe Systems Incorporated
7
18. A dialog will appear prompting for values for empID, firstName and lastName. Enter the
following values and click OK.
19. A dialog will appear stating that the invocation completed successfully (in the title) and the
process has no output variables. Click OK.
Note: If an invocation error appears, check the syntax of the SQL statement and invoke the process
again.
20. To verify that the record was inserted into the database, open Windows Explorer and navigate
to C:\AdobeTraining\Doc_Services\Foundation\Execute_SQL_Statement.
21. Double-click on the showEmployees.bat file.
Note: This bat file executes a SELECT * FROM employee SQL statement on the database. It then
lists all the records returned by the statement.
22. Verify that 2 employees have been inserted into the database.
8
Copyright © 2011 Adobe Systems Incorporated
Summary
• The Execute SQL Statement operation executes a SQL statement and outputs the number
of affected rows
• The Execute SQL Statement operation is typically used for SQL statements that do not
return a result set, such as Insert, Update, and Delete statements
Copyright © 2011 Adobe Systems Incorporated
9
Review
1. What happens when a Query Single Row operation has a SQL Statement that returns multiple
rows?
2. When creating a SQL statement using the SQL Statement Info Editor, what is the purpose of the
Use Parameterized Query option?
Adobe Systems Incorporated
345 Park Avenue
San Jose, CA 95110-2704
USA
www.adobe.com
Adobe, Acrobat, Adobe AIR, AIR, Distiller, Flash, Flash Builder, Flash Catalyst, Flex, Adobe Digital Enterprise Platform, MXML,
PostScript, Reader, SiteCatalyst, SearchCenter, Discover, Recommendations, Insight, Test&Target, ReportBuilder, Survey,
Search&Promote, and Social Media are either registered trademarks or trademarks of Adobe Systems Incorporated in the United
States and/or other countries.
© 2011 Adobe Systems Incorporated. All rights reserved.