Class NamedParameterStatement
- java.lang.Object
 - 
- com.identityworksllc.iiq.common.query.AbstractNamedParameterStatement<PreparedStatement>
 - 
- com.identityworksllc.iiq.common.query.NamedParameterStatement
 
 
 
- 
- All Implemented Interfaces:
 AutoCloseable
public final class NamedParameterStatement extends AbstractNamedParameterStatement<PreparedStatement>
Named parameter prepared statement wrapper, derived from various examples around the Internet.Rather than setting arguments by position, you can set them by name, the way Hibernate or certain JDBC drivers permit.
Tokens have the form
:nameand must be alphanumeric.The same tokens can be re-used more than once in your query.
NamedParameterStatement stmt = new NamedParameterStatement( connection, "select id from spt_identity where (extended3 = :username or name = :username) and extended4 = :department" ); stmt.setString("username", someUsername); stmt.setString("department", someDepartment); // Use the statement like any otherIf you attempt to set a token that does not exist, such as
stmt.setString("xyz", str)in the above example, the default behavior is to throw anIllegalArgumentException. You can useAbstractNamedParameterStatement.setAllowMissingAttributes(boolean)to disable this behavior. 
- 
- 
Field Summary
- 
Fields inherited from class com.identityworksllc.iiq.common.query.AbstractNamedParameterStatement
allowMissingAttributes, connection, indexMap, statement 
 - 
 
- 
Constructor Summary
Constructors Constructor Description NamedParameterStatement(Connection connection, String query)Creates a NamedParameterStatement. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBatch()Adds the current row to the batchbooleanexecute()Executes the statement.ResultSetexecuteQuery()Executes the statement and returns a result setintexecuteUpdate()Executes the statement and returns the update countvoidsetArray(String name, List<String> value)Sets a parameter to an array.voidsetBlob(String name, byte[] blob)Sets the given byte array as a Blob input to the statementvoidsetBlob(String name, Blob blob)Sets the given byte array as a Blob input to the statementvoidsetClob(String name, Reader clob)Sets a parameter to a clobvoidsetClob(String name, String clob)Sets a parameter to a clobvoidsetClob(String name, Clob clob)Sets a parameter to a clobvoidsetDate(String name, Date value)Sets a parameter.voidsetDate(String name, Instant value)Sets a parameter to a Java time instant.voidsetDate(String name, LocalDateTime value)Sets a parameter to a Java time instant.voidsetDate(String name, Date value)Sets a parameter to a Java date.voidsetDouble(String name, double value)Sets a parameter.voidsetInt(String name, int value)Sets a parameter.voidsetLong(String name, long value)Sets a parameter.voidsetNull(String name)Sets a parameter to null, assuming the type to be VARCHAR.voidsetNull(String name, int type)Sets a typed parameter to nullvoidsetObject(String name, Object value)Sets a parameter to the given object.voidsetString(String name, String value)Sets a parameter.voidsetTimestamp(String name, Timestamp value)Sets a parameter.voidsetXml(String name, Object xmlObject)Serializes the input object into XML and then adds it to the query as a CLOB.- 
Methods inherited from class com.identityworksllc.iiq.common.query.AbstractNamedParameterStatement
close, executeBatch, getIndexes, getParameterNames, getStatement, isClosed, parse, setAllowMissingAttributes, setFetchDirection, setFetchSize, setMaxRows, setParameters, setQueryTimeout 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
NamedParameterStatement
public NamedParameterStatement(Connection connection, String query) throws SQLException
Creates a NamedParameterStatement.Wraps a call to
Connection.prepareStatement(java.lang.String).- Parameters:
 connection- the database connectionquery- the parameterized query- Throws:
 SQLException- if the statement could not be created
 
 - 
 
- 
Method Detail
- 
addBatch
public void addBatch() throws SQLException
Adds the current row to the batch- Specified by:
 addBatchin classAbstractNamedParameterStatement<PreparedStatement>- Throws:
 SQLException- The batch- See Also:
 PreparedStatement.addBatch(),PreparedStatement.addBatch()
 
- 
execute
public boolean execute() throws SQLException
Executes the statement.- Returns:
 - true if the first result is a 
ResultSet - Throws:
 SQLException- if an error occurred- See Also:
 PreparedStatement.execute()
 
- 
executeQuery
public ResultSet executeQuery() throws SQLException
Executes the statement and returns a result set- Returns:
 - The result set
 - Throws:
 SQLException- on errors
 
- 
executeUpdate
public int executeUpdate() throws SQLException
Executes the statement and returns the update count- Returns:
 - The update count
 - Throws:
 SQLException- on errors
 
- 
setArray
public void setArray(String name, List<String> value) throws SQLException
Sets a parameter to an array.Note that this is not supported in all database engines (particularly, not in MySQL)
- Parameters:
 name- The name of the fieldvalue- The list to change to an array- Throws:
 SQLException- if a failure generating the array occurs
 
- 
setBlob
public void setBlob(String name, Blob blob) throws SQLException
Sets the given byte array as a Blob input to the statement- Parameters:
 name- The parameter nameblob- The blob- Throws:
 SQLException- on failures
 
- 
setBlob
public void setBlob(String name, byte[] blob) throws SQLException
Sets the given byte array as a Blob input to the statement- Parameters:
 name- The parameter nameblob- The blob- Throws:
 SQLException- on failures setting the blob or reading the byte array
 
- 
setClob
public void setClob(String name, Reader clob) throws SQLException
Sets a parameter to a clob- Parameters:
 name- The named parameterclob- The clob to set- Throws:
 SQLException- on failures
 
- 
setClob
public void setClob(String name, String clob) throws SQLException
Sets a parameter to a clob- Parameters:
 name- The named parameterclob- The clob to set- Throws:
 SQLException- on failures
 
- 
setClob
public void setClob(String name, Clob clob) throws SQLException
Sets a parameter to a clob- Parameters:
 name- The named parameterclob- The clob to set- Throws:
 SQLException- on failures
 
- 
setDate
public void setDate(String name, LocalDateTime value) throws SQLException
Sets a parameter to a Java time instant.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setDate(int, Date)
 
- 
setDate
public void setDate(String name, Instant value) throws SQLException
Sets a parameter to a Java time instant.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setDate(int, Date)
 
- 
setDate
public void setDate(String name, Date value) throws SQLException
Sets a parameter to a Java date.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setDate(int, Date)
 
- 
setDate
public void setDate(String name, Date value) throws SQLException
Sets a parameter.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setDate(int, Date)
 
- 
setDouble
public void setDouble(String name, double value) throws SQLException
Sets a parameter.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setDouble(int, double)
 
- 
setInt
public void setInt(String name, int value) throws SQLException
Sets a parameter.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setInt(int, int)
 
- 
setLong
public void setLong(String name, long value) throws SQLException
Sets a parameter.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setLong(int, long)
 
- 
setNull
public void setNull(String name) throws SQLException
Sets a parameter to null, assuming the type to be VARCHAR.- Parameters:
 name- parameter name- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setNull(int, int)
 
- 
setNull
public void setNull(String name, int type) throws SQLException
Sets a typed parameter to null- Parameters:
 name- parameter nametype- The SQL type of the argument to set- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setNull(int, int)
 
- 
setObject
public void setObject(String name, Object value) throws SQLException
Sets a parameter to the given object.If the object is a SailPointObject, the parameter will be set as to its ‘id’ as a string instead.
- Specified by:
 setObjectin classAbstractNamedParameterStatement<PreparedStatement>- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setObject(int, java.lang.Object)
 
- 
setString
public void setString(String name, String value) throws SQLException
Sets a parameter.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setString(int, java.lang.String)
 
- 
setTimestamp
public void setTimestamp(String name, Timestamp value) throws SQLException
Sets a parameter.- Parameters:
 name- parameter namevalue- parameter value- Throws:
 SQLException- if an error occurredIllegalArgumentException- if the parameter does not exist- See Also:
 PreparedStatement.setTimestamp(int, java.sql.Timestamp)
 
- 
setXml
public void setXml(String name, Object xmlObject) throws SQLException
Serializes the input object into XML and then adds it to the query as a CLOB.- Parameters:
 name- The field namexmlObject- The XML object- Throws:
 SQLException- if any failures occur
 
 - 
 
 -