Download Selecting Data from a Database

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

Concurrency control wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Database wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Functional Database Model wikipedia , lookup

Versant Object Database wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Adobe Enterprise Technical Enablement
Selecting Data from a Database
In this topic, you will learn about the Query Single Row operation and how it is used to
interact with databases.
Objectives
After completing this unit, you should be able to
• Use the Query Single Row operation to select data from a database
Concepts
In this topic, you will learn about the following concepts
• Selecting database data
Copyright © 2011 Adobe Systems Incorporated
1
Selecting database data
• The JDBC service offers two operations to select database data
■ Query Single Row
■ Query Multiple Rows as XML
Query Single Row operation
• The Query Single Row operation queries the database using a SQL statement and saves the
first row of the result set
■ Located in Foundation > JDBC - 1.0
Figure 1: Locating the Query Single Row operation of the JDBC service
Setting Query Single Row operation properties
• When a Query Single Row 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
2
Copyright © 2011 Adobe Systems Incorporated
■ Data Mapping
– the locations in the process data model to use for saving the data in the first row
of the query result set
– Specified through the SQL Results Mapping Editor
Figure 2: Query Single Row properties
Copyright © 2011 Adobe Systems Incorporated
3
SQL Results Mapping Editor
• The SQL Results Mapping Editor is used to specify the data locations in the process for
values returned as part of the result set
■ Opened by clicking the ellipsis button next to the Data Mapping property in the
Properties view
Figure 3: SQL Results Mapping Editor
• Parse Query
■ Determines column names from the SQL statement that is specified in the SQL
Statement property
■ Can only be used if the SQL statement explicitly names the columns
• Process Metadata
■ Retrieves column names from the database server
■ A request is sent to the database server to process the query and return metadata
about the query
■ The list of columns is determined from the returned metadata
– Index - gives the ordinal position of the column in the result set
– Column Name - name of the database table column
– Process Variable - An XPath expression that resolves to the process data location
to use to store the data from the corresponding column
4
Copyright © 2011 Adobe Systems Incorporated
Task 1: Selecting a single row of data
In this task, you will perform the following
• Open a process
• Configure a Query Single Row operation
• Test the process
Setup
1. Create the adobetraining database.
2. Import the Selecting_Database_Data.lca file.
Steps
Open a process
1. Login to the Workbench.
2. Open the Selecting_Database_Data application.
3. Expand the Processes folder, right-click the SelectingDatabaseData process and select
Check Out.
4. Double-click the SelectingDatabaseData process to open it.
5. Create an additional process variable named rowsReturned of type int and mark the
variable as Output.
6. Move the Insert Row in DB operation to the right, leaving enough space to add another
operation in front of it.
Configure a Query Single Row operation
7. From the process diagram palette, drag the Activity Picker activity onto your process diagram
and drop it to the left of the Insert Row in DB operation.
8. In the Define Activity dialog box, expand the Foundation category.
9. From the JDBC service, select the Query Single Row operation and click OK.
10. Select the Query Single Row operation and set the following properties.
• Name: Check if Employee Exists
• Datasource name (literal value): java:/AdobeTraining
• Number of Rows Retrieved (variable): rowsReturned
11. For the SQL Statement property, click on the ellipsis to access the SQL Statement Info Editor
and set the following properties.
• SQL Statement: SELECT id FROM employee WHERE id=?
• Use Parameterized Query: checked
• Create the following parameter
■ Index: 1
Copyright © 2011 Adobe Systems Incorporated
5
12.
13.
14.
15.
16.
17.
18.
■ Type: STRING
■ Value: /process_data/@empID
For the Data Mapping property, click on the ellipsis to access the SQL Results Mapping
Editor.
Click on the Parse Query button. Confirm that an index for the id column is created.
For the id column, set the Process Variable to /process_data/@empID and click OK.
Right click on the Check if Employee Exists operation and set it to be the Start Activity.
Draw a route connecting the two operations.
Select the route and add the following condition.
• expr1: /process_data/@rowsReturned
• operator: =
• expr2: 0
Confirm that the process looks like the figure below.
19. Save the process and Deploy the application.
Test the process
20. Right-click in an empty area of the process diagram and select Invoke Process...
21. A dialog will appear prompting for values for empID, firstName and lastName. Enter the
following values and click OK.
• empID: 200
• firstName: Alex
• lastName: Pink
22. Confirm that the process returns a rowsReturned value of 0. This value is returned because
Employee ID 200 does not exist in the database.
6
Copyright © 2011 Adobe Systems Incorporated
Note: If an invocation error appears, check the syntax of the SQL statement and try running the
process again.
23. To verify that the record was inserted into the database, open Windows Explorer and
navigate to C:\AdobeTraining\Doc_Services\Foundation\Selecting_Database_Data.
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.
24. Verify that Alex Pink has been inserted into the database.
25. Invoke the process again with the following values.
• empID: 200
• firstName: Rye
• lastName: Woodard
26. Confirm that the process returns a rowsReturned value of 1. This value is returned because
Employee ID 200 exists in the database.
Copyright © 2011 Adobe Systems Incorporated
7
Summary
• The Query Single Row operation queries a data source and generates a variable with the
number of records
• The SQL Results Mapping Editor is used to specify the data locations in the process for values
returned as part of the result set
8
Copyright © 2011 Adobe Systems Incorporated
Review
1. Give an example of when you would use the Query Single Row operation in a process.
2. What is the purpose of the SQL Results Mapping Editor?
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.