WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

Endpoint
Name:sqlPSQuery
Description:The active:sqlPSQuery service retrieves information from a relational database (RDBMS) using SQL prepared statement with parameter substitution.
Id:mod-db:sqlPSQuery
Category:accessor
Identifier Syntax

sqlPSQuery is an accessor using Active URI syntax with the following base identifiers:

Base
active:sqlPSQuery

and the following arguments: (for more details on argument passing details see here)

ArgumentRulesTypingDescription
operand
Mandatory
Representation (java.lang.Object)SQL query statement to be executed
configuration
Optional
Representation (java.lang.Object)Connection pool configuration
param
0 ... infinity
Representation (java.lang.Object)Prepared Statement Parameter (order dependent)
Request Verbs

The following verb is supported:

Verb
SOURCE
Response

The response representation of this accessor for SOURCE requests is unknown.

This accessor throws no documented exceptions.

Import Requirements

To use sqlPSQuery accessor you must import the module urn:org:netkernel:mod:db:

<import>
  <uri>urn:org:netkernel:mod:db</uri>
</import>

When a request with the SOURCE verb is issued to active:sqlPSQuery the SQL query statement specified in the required operand argument is used to create a prepared statement with the database connection pool specified in the optional configuration argument. (If the configuration argument is not supplied then the service issues a request for the resource res:/etc/ConfigRDBMS.xml in the current space.)

The argument operand is requested by the service as a DeterminateStringRepresentation which allows the supplied representation type to be any of the forms that can be transrepted to a DeterminateString.

Parameter Substitution

Parameters in the prepared statement SQL are denoted by a question mark ?. For example

SELECT * FROM users WHERE age < ? AND eyecolor=?;

Parameters are order dependent. Each delimited parameter must be provided as a param argument on the request. The java class type of the param argument is determined during the preparation of the statement with the database. The param argument will be SOURCEd with a Java class determined by the JDBC PreparedStatement using the ParameterMetadata. It is essential that the supplied parameter either be of the correct type, or is transreptable to the correct type.

Response

By default, the response representation is returned as an HDS structure in which a resultset node contains a row node for each row returned by the query.

The response representation takes the same form as documented for active:sqlQuery

Example

The following code implements an example prepared statement query with two parameters.

sql="SELECT firstname, lastname, age FROM users WHERE firstname=? AND age=? ;"
request = context.createRequest("active:sqlPSQuery");
request.addArgumentByValue("operand", sql)
request.addArgumentByValue("param", "Mary");
request.addArgumentByValue("param", 21);
hds = context.issueRequest(request);