Cernunnos Manual


<sql-query>

Description:

Performs a specified query, then invokes SUBTASKS once for each row in the result set. For each iteration of SUBTASKS, column values will be registered as request attributes both under (1) the column name (all uppercase), and (2) the column index (starting with 1).

Reagents:

Name XPath Description Reagent Type Expected Type Required
DATA_SOURCE @data-source The DataSource to use for executing the SQL. If omitted the request attribute under the name 'SqlAttributes.DATA_SOURCE' will be used PHRASE javax.sql.DataSource No
CONNECTION @connection
** DEPRECATED ** since 1.0.1

Use DATA_SOURCE instead

Optional Connection object. The default is the value of the 'SqlAttributes.CONNECTION' request attribute (if specified) or null.
PHRASE java.sql.Connection No
SQL sql The SQL query statement that will be executed. PHRASE java.lang.String Yes
PARAMETERS parameter/@value The parameters (if any) for the PreparedStatement that will perform this query. NODE_LIST java.util.List No
SUBTASKS subtasks/* The set of tasks that are children of this query task. NODE_LIST java.util.List No
EMPTY_RESULT empty-result/* The set of tasks that will be executed if the query returns no results. NODE_LIST java.util.List No

Examples:

Reads database connection information from a properties file, makes a connection, writes each name from the 'users' table to the screen:

 
       
        <properties location="build/WEB-INF/classes/properties/rdbm.properties"> 
          <sql-datasource driver="${req(jdbcDriver)}" password="${req(jdbcPassword)}" url="${req(jdbcUrl)}" username="${req(jdbcUser)}"> 
            <sql-query> 
              <sql>SELECT user_name FROM users</sql>  
              <subtasks> 
                <echo>${req(1)},</echo> 
              </subtasks> 
            </sql-query> 
          </sql-datasource> 
        </properties>