Skip to content

pQuery.doConditionQuery

Signature: pQuery.doConditionQuery(connection, timestampFormat*, timeoutSeconds*)

Returns: Object value - the typed value of the first column of the first row of the result set, or null when no row matched

Execute a parameterized database query and return the value of the first column of the first row of the result set. All other columns and rows are ignored.

Note

This method uses the java.sql.PreparedStatement.execute() method.

Note

When no row matches, null is returned, which makes this the natural call for an existence check.

Parameters

Type Name Description Default
String connection the name of the database connection
String timestampFormat* (optional) the format string to use for timestamp fields yyyyMMddHHmmss
Integer timeoutSeconds* (optional) the SQL query timeout in seconds; 0 means no timeout 0

Example

// Create the pQuery object with the query to be executed
var pQuery = qie.getParameterizedQuery("select name from patient where patient_id = :patientId");

// a matching row returns just the first column of that row
pQuery.setInt("patientId", 1);
var name = pQuery.doConditionQuery("EMR Database"); // "Ada Lovelace"

// no matching row returns null, which makes this the natural existence check
pQuery.setInt("patientId", 999);
if (pQuery.doConditionQuery("EMR Database") != null) {
   // the patient exists
}