Skip to content

pQuery.setObject

Signature: pQuery.setObject(parameterName, value, targetSqlType*, scaleOrLength*)

Returns: ParameterizedQuery pQuery - this ParameterizedQuery object. To see what methods can be used on a ParameterizedQuery, refer to the 'Parameterized Query' functions.

Sets the parameterName to the given Java Object value.

Note

The JDBC specification specifies a standard mapping from Java Object types to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database. See the JavaDoc for java.sql.Types. For more information see the JavaDoc for the setObject method on java.sql.PreparedStatement.

Note

The parameterName may include the parameter prefix character (colon ':' or at sign '@') but is not required. For example: ':fieldValue' and 'fieldValue' will reference the same named parameter.

Parameters

Type Name Description Default
String parameterName the name of the parameter
Object value the value to use for parameterName
Integer targetSqlType* (optional) the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type. null
Integer scaleOrLength* (optional) for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, this is the number of digits after the decimal point. For Java Object types InputStream and Reader, this is the length of the data in the stream or reader. For all other types, this value will be ignored. null

Example

// Create the pQuery object
var pQuery = qie.getParameterizedQuery(
    "update patient\n" +
    "set balance = :birthYear\n" +
    "where patient_id = :personId"
);

// Identify the row
pQuery.setLong("personId", 1001);

// Value determined at runtime (could be Integer, Long, or null)
var birthYear = 1985;

// Let JDBC map the Java type to SQL
pQuery.setObject("birthYear", birthYear);

// Execute the update
pQuery.doQuery("EMR Database");