Package com.iizix.sql

Class NamedParameterStatement

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class NamedParameterStatement
    extends java.lang.Object
    implements java.lang.AutoCloseable
    The input properties parameter statement for JDBC that is prepared and filled with the parameters from the named host variables as specified in the Database connector com.iziix.db.prop.InputProps with the com.iziix.db.prop.InputVariable's containing mappings to VSField's.

    This class wraps around a PreparedStatement and enables iizi SQL statement preparation. It also makes it easier for the com.iziix.db.api.IQueryStatementInput custom processor to set their values as required.

    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static java.lang.ObjectNULL_VALUE
      The special NULL value object for a set parameter.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      NamedParameterStatement​(java.sql.Connection connection, java.lang.String query)
      Creates a NamedParameterStatement.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidclose()
      Closes the statement.
      int[]getIndicies​(java.lang.String name)
      Returns the indicies for a parameter.
      java.util.Map<java.lang.String,​IntArrayList>getIndiciesMap()
      Gets the map of names of host variables and their indicies.
      java.lang.StringgetOriginalQuery()
      Gets the original query.
      java.lang.String[]getParameterNames()
      Gets the list of parameter names.
      java.lang.StringgetParsedQuery()
      Returns the parsed query containing question marks.
      java.sql.PreparedStatementgetPreparedStatement()
      Returns the prepares statement that can be used to set parameter using indicies.
      static java.lang.Stringparse​(java.lang.String query, java.util.Map<java.lang.String,​IntArrayList> map)
      Parses the query statement.
      voidreset()
      Resets the statement to release memory, i.e.
      voidsetBigDecimal​(java.lang.String name, java.math.BigDecimal x)
      Sets the designated parameter to the given java.math.BigDecimal value.
      voidsetBoolean​(java.lang.String name, boolean x)
      Sets the designated parameter to the given Java boolean value.
      voidsetByte​(java.lang.String name, byte x)
      Sets the designated parameter to the given Java byte value.
      voidsetBytes​(java.lang.String name, byte[] x)
      Sets the designated parameter to the given Java array of bytes.
      voidsetDate​(java.lang.String name, java.sql.Date x)
      Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.
      voidsetDate​(java.lang.String name, java.sql.Date x, java.util.Calendar cal)
      Sets the designated parameter to the given java.sql.Date value, using the given Calendar object.
      voidsetDouble​(java.lang.String name, double x)
      Sets the designated parameter to the given Java double value.
      voidsetFloat​(java.lang.String name, float x)
      Sets the designated parameter to the given Java float value.
      voidsetInt​(java.lang.String name, int x)
      Sets the designated parameter to the given Java int value.
      voidsetLong​(java.lang.String name, long x)
      Sets the designated parameter to the given Java long value.
      voidsetNull​(java.lang.String name, int sqlType)
      Sets the designated parameter to SQL NULL.
      voidsetNull​(java.lang.String name, int sqlType, java.lang.String typeName)
      Sets the designated parameter to SQL NULL.
      voidsetObject​(java.lang.String name, java.lang.Object x)
      Sets the value of the designated parameter using the given object.
      voidsetObject​(java.lang.String name, java.lang.Object x, int targetSqlType)
      Sets the value of the designated parameter with the given object.
      voidsetObject​(java.lang.String name, java.lang.Object x, int targetSqlType, int scaleOrLength)
      Sets the value of the designated parameter with the given object.
      voidsetObject​(java.lang.String name, java.lang.Object x, java.sql.SQLType targetSqlType)
      Sets the value of the designated parameter with the given object.
      voidsetObject​(java.lang.String name, java.lang.Object x, java.sql.SQLType targetSqlType, int scaleOrLength)
      Sets the value of the designated parameter with the given object.
      voidsetRowId​(java.lang.String name, java.sql.RowId x)
      Sets the designated parameter to the given java.sql.RowId object.
      voidsetShort​(java.lang.String name, short x)
      Sets the designated parameter to the given Java short value.
      voidsetString​(java.lang.String name, java.lang.String x)
      Sets the designated parameter to the given Java String value.
      voidsetTime​(java.lang.String name, java.sql.Time x)
      Sets the designated parameter to the given java.sql.Time value.
      voidsetTime​(java.lang.String name, java.sql.Time x, java.util.Calendar cal)
      Sets the designated parameter to the given java.sql.Time value, using the given Calendar object.
      voidsetTimestamp​(java.lang.String name, java.sql.Timestamp x)
      Sets the designated parameter to the given java.sql.Timestamp value.
      voidsetTimestamp​(java.lang.String name, java.sql.Timestamp x, java.util.Calendar cal)
      Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object.
      voidsetURL​(java.lang.String name, java.net.URL x)
      Sets the designated parameter to the given java.net.URL value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NULL_VALUE

        public static final java.lang.Object NULL_VALUE
        The special NULL value object for a set parameter.
    • Constructor Detail

      • NamedParameterStatement

        public NamedParameterStatement​(java.sql.Connection connection,
                                       java.lang.String query)
                                throws java.sql.SQLException
        Creates a NamedParameterStatement. Wraps a call to connection. prepareStatement.
        Parameters:
        connection - The database connection.
        query - The parameterized query.
        Throws:
        java.sql.SQLException - If the statement could not be created.
    • Method Detail

      • parse

        public static java.lang.String parse​(java.lang.String query,
                                             java.util.Map<java.lang.String,​IntArrayList> map)
        Parses the query statement. Upon return, the map contains the host name parameters encountered in the query and a list of integer indicies that are one-based for JDBC usage.
        Parameters:
        query - The query statement.
        map - The map is filled with names and their JDBC variable indicies upon return.
        Returns:
        Parsed query statement.
      • getPreparedStatement

        public java.sql.PreparedStatement getPreparedStatement()
        Returns the prepares statement that can be used to set parameter using indicies. For certain advanced statement operation not provided in this class, you will have to use this method to retrieve the statement and to call the method required of the statement directly. The indices of the parameter can be retrieved using getIndicies(String name).
        Returns:
        The prepared statement.
      • getParsedQuery

        public java.lang.String getParsedQuery()
        Returns the parsed query containing question marks.

        This String is used to prepare the statement for JDBC.

        Returns:
        The parsed query where the ":variableNames" are replaced with "?".
      • getOriginalQuery

        public java.lang.String getOriginalQuery()
        Gets the original query.
        Returns:
        The original query containing the host variable parameters.
      • getParameterNames

        public java.lang.String[] getParameterNames()
        Gets the list of parameter names.
        Returns:
        An array with the parameter names, never null.
      • getIndicies

        public int[] getIndicies​(java.lang.String name)
                          throws NamedParameterException
        Returns the indicies for a parameter.
        Parameters:
        name - Parameter name.
        Returns:
        The parameter indicies, where an index is one-based for JDBC usage.
        Throws:
        NamedParameterException - If the parameter does not exist.
      • getIndiciesMap

        public java.util.Map<java.lang.String,​IntArrayList> getIndiciesMap()
        Gets the map of names of host variables and their indicies.
        Returns:
        The map.
      • reset

        public void reset()
        Resets the statement to release memory, i.e. parameters and set values.

        This method is not intended to be called by client code, it is used by the framework.

      • setNull

        public void setNull​(java.lang.String name,
                            int sqlType)
                     throws java.sql.SQLException
        Sets the designated parameter to SQL NULL.

        Note: You must specify the parameter's SQL type.

        Parameters:
        name - The name of the parameter.
        sqlType - The SQL type code defined in java.sql.Types.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        java.sql.SQLFeatureNotSupportedException - if sqlType is a ARRAY, BLOB, CLOB, DATALINK, JAVA_OBJECT, NCHAR, NCLOB, NVARCHAR, LONGNVARCHAR, REF, ROWID, SQLXML or STRUCT data type and the JDBC driver does not support this data type.
        NamedParameterException - if the parameter does not exist.
      • setBoolean

        public void setBoolean​(java.lang.String name,
                               boolean x)
                        throws java.sql.SQLException
        Sets the designated parameter to the given Java boolean value. The driver converts this to an SQL BIT or BOOLEAN value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
        NamedParameterException - if the parameter does not exist.
      • setByte

        public void setByte​(java.lang.String name,
                            byte x)
                     throws java.sql.SQLException
        Sets the designated parameter to the given Java byte value. The driver converts this to an SQL TINYINT value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setShort

        public void setShort​(java.lang.String name,
                             short x)
                      throws java.sql.SQLException
        Sets the designated parameter to the given Java short value. The driver converts this to an SQL SMALLINT value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setInt

        public void setInt​(java.lang.String name,
                           int x)
                    throws java.sql.SQLException
        Sets the designated parameter to the given Java int value. The driver converts this to an SQL INTEGER value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setLong

        public void setLong​(java.lang.String name,
                            long x)
                     throws java.sql.SQLException
        Sets the designated parameter to the given Java long value. The driver converts this to an SQL BIGINT value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setFloat

        public void setFloat​(java.lang.String name,
                             float x)
                      throws java.sql.SQLException
        Sets the designated parameter to the given Java float value. The driver converts this to an SQL REAL value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setDouble

        public void setDouble​(java.lang.String name,
                              double x)
                       throws java.sql.SQLException
        Sets the designated parameter to the given Java double value. The driver converts this to an SQL DOUBLE value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setBigDecimal

        public void setBigDecimal​(java.lang.String name,
                                  java.math.BigDecimal x)
                           throws java.sql.SQLException
        Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to an SQL NUMERIC value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setString

        public void setString​(java.lang.String name,
                              java.lang.String x)
                       throws java.sql.SQLException
        Sets the designated parameter to the given Java String value. The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's size relative to the driver's limits on VARCHAR values) when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setBytes

        public void setBytes​(java.lang.String name,
                             byte[] x)
                      throws java.sql.SQLException
        Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARY values) when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setDate

        public void setDate​(java.lang.String name,
                            java.sql.Date x)
                     throws java.sql.SQLException
        Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application. The driver converts this to an SQL DATE value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setTime

        public void setTime​(java.lang.String name,
                            java.sql.Time x)
                     throws java.sql.SQLException
        Sets the designated parameter to the given java.sql.Time value. The driver converts this to an SQL TIME value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setTimestamp

        public void setTimestamp​(java.lang.String name,
                                 java.sql.Timestamp x)
                          throws java.sql.SQLException
        Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an SQL TIMESTAMP value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setObject

        public void setObject​(java.lang.String name,
                              java.lang.Object x,
                              int targetSqlType)
                       throws java.sql.SQLException
        Sets the value of the designated parameter with the given object. This method is similar to setObject(String name, Object x, int targetSqlType, int scaleOrLength), except that it assumes a scale of zero.
        Parameters:
        name - The name of the parameter.
        x - The object containing the input parameter value.
        targetSqlType - The SQL type (as defined in java.sql.Types) to be sent to the database.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        java.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support the specified targetSqlType.
        NamedParameterException - if the parameter does not exist.
        See Also:
        Types
      • setObject

        public void setObject​(java.lang.String name,
                              java.lang.Object x)
                       throws java.sql.SQLException
        Sets the value of the designated parameter using the given object.

        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.

        Note that this method may be used to pass datatabase-specific abstract data types, by using a driver-specific Java type. If the object is of a class implementing the interface SQLData, the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, NClob, Struct, java.net.URL, RowId, SQLXML or Array, the driver should pass it to the database as a value of the corresponding SQL type.

        Note: Not all databases allow for a non-typed Null to be sent to the backend. For maximum portability, the setNull or the setObject(int parameterIndex, Object x, int sqlType) method should be used instead of setObject(int parameterIndex, Object x).

        Note: This method throws an exception if there is an ambiguity, for example, if the object is of a class implementing more than one of the interfaces named above.

        Parameters:
        name - The name of the parameter.
        x - The object containing the input parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs; this method is called on a closed PreparedStatement or the type of the given object is ambiguous.
        NamedParameterException - if the parameter does not exist.
      • setDate

        public void setDate​(java.lang.String name,
                            java.sql.Date x,
                            java.util.Calendar cal)
                     throws java.sql.SQLException
        Sets the designated parameter to the given java.sql.Date value, using the given Calendar object. The driver uses the Calendar object to construct an SQL DATE value, which the driver then sends to the database. With a Calendar object, the driver can calculate the date taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        cal - The Calendar object the driver will use to construct the date.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setTime

        public void setTime​(java.lang.String name,
                            java.sql.Time x,
                            java.util.Calendar cal)
                     throws java.sql.SQLException
        Sets the designated parameter to the given java.sql.Time value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIME value, which the driver then sends to the database. With a Calendar object, the driver can calculate the time taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        cal - The Calendar object the driver will use to construct the time.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setTimestamp

        public void setTimestamp​(java.lang.String name,
                                 java.sql.Timestamp x,
                                 java.util.Calendar cal)
                          throws java.sql.SQLException
        Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIMESTAMP value, which the driver then sends to the database. With a Calendar object, the driver can calculate the timestamp taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        cal - The Calendar object the driver will use to construct the timestamp.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        NamedParameterException - if the parameter does not exist.
      • setNull

        public void setNull​(java.lang.String name,
                            int sqlType,
                            java.lang.String typeName)
                     throws java.sql.SQLException
        Sets the designated parameter to SQL NULL. This version of the method setNull should be used for user-defined types and REF type parameters. Examples of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and named array types.

        Note: To be portable, applications must give the SQL type code and the fully-qualified SQL type name when specifying a NULL user-defined or REF parameter. In the case of a user-defined type the name is the type name of the parameter itself. For a REF parameter, the name is the type name of the referenced type. If a JDBC driver does not need the type code or type name information, it may ignore it.

        Although it is intended for user-defined and Ref parameters, this method may be used to set a null parameter of any JDBC type. If the parameter does not have a user-defined or REF type, the given typeName is ignored.

        Parameters:
        name - The name of the parameter.
        sqlType - A value from java.sql.Types.
        typeName - The fully-qualified name of an SQL user-defined type; ignored if the parameter is not a user-defined type or REF.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        java.sql.SQLFeatureNotSupportedException - if sqlType is a ARRAY, BLOB, CLOB, DATALINK, JAVA_OBJECT, NCHAR, NCLOB, NVARCHAR, LONGNVARCHAR, REF, ROWID, SQLXML or STRUCT data type and the JDBC driver does not support this data type or if the JDBC driver does not support this method.
        NamedParameterException - if the parameter does not exist.
      • setURL

        public void setURL​(java.lang.String name,
                           java.net.URL x)
                    throws java.sql.SQLException
        Sets the designated parameter to the given java.net.URL value. The driver converts this to an SQL DATALINK value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The java.net.URL object to be set.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        java.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support this method.
        NamedParameterException - if the parameter does not exist.
      • setObject

        public void setObject​(java.lang.String name,
                              java.lang.Object x,
                              int targetSqlType,
                              int scaleOrLength)
                       throws java.sql.SQLException
        Sets the value of the designated parameter with the given object. If the second argument is an InputStream then the stream must contain the number of bytes specified by scaleOrLength. If the second argument is a Reader then the reader must contain the number of characters specified by scaleOrLength. If these conditions are not true the driver will generate a SQLException when the prepared statement is executed.

        The given Java object will be converted to the given targetSqlType before being sent to the database. If the object has a custom mapping (is of a class implementing the interface SQLData), the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, NClob, Struct, java.net.URL, or Array, the driver should pass it to the database as a value of the corresponding SQL type.

        Note that this method may be used to pass database-specific abstract data types.

        Parameters:
        name - The name of the parameter.
        x - The object containing the input parameter value.
        targetSqlType - The SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.
        scaleOrLength - 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.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs; this method is called on a closed PreparedStatement or if the Java Object specified by x is an InputStream or Reader object and the value of the scale parameter is less than zero
        java.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support the specified targetSqlType
        NamedParameterException - if the parameter does not exist.
        See Also:
        Types
      • setRowId

        public void setRowId​(java.lang.String name,
                             java.sql.RowId x)
                      throws java.sql.SQLException
        Sets the designated parameter to the given java.sql.RowId object. The driver converts this to a SQL ROWID value when it sends it to the database.
        Parameters:
        name - The name of the parameter.
        x - The parameter value.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement.
        java.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support this method.
        NamedParameterException - if the parameter does not exist.
      • setObject

        public void setObject​(java.lang.String name,
                              java.lang.Object x,
                              java.sql.SQLType targetSqlType,
                              int scaleOrLength)
                       throws java.sql.SQLException
        Sets the value of the designated parameter with the given object.

        If the second argument is an InputStream then the stream must contain the number of bytes specified by scaleOrLength. If the second argument is a Reader then the reader must contain the number of characters specified by scaleOrLength. If these conditions are not true the driver will generate a SQLException when the prepared statement is executed.

        The given Java object will be converted to the given targetSqlType before being sent to the database.

        If the object has a custom mapping (is of a class implementing the interface SQLData), the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, NClob, Struct, java.net.URL, or Array, the driver should pass it to the database as a value of the corresponding SQL type.

        Note that this method may be used to pass database-specific abstract data types.

        The default implementation will throw SQLFeatureNotSupportedException.

        Parameters:
        name - The name of the parameter.
        x - The object containing the input parameter value.
        targetSqlType - The SQL type to be sent to the database. The scale argument may further qualify this type.
        scaleOrLength - for java.sql.JDBCType.DECIMAL or java.sql.JDBCType.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.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement or if the Java Object specified by x is an InputStream or Reader object and the value of the scale parameter is less than zero
        java.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support the specified targetSqlType
        NamedParameterException - if the parameter does not exist.
        See Also:
        JDBCType, SQLType
      • setObject

        public void setObject​(java.lang.String name,
                              java.lang.Object x,
                              java.sql.SQLType targetSqlType)
                       throws java.sql.SQLException
        Sets the value of the designated parameter with the given object.

        This method is similar to setObject(String name, Object x, SQLType targetSqlType, int scaleOrLength), except that it assumes a scale of zero.

        The default implementation will throw SQLFeatureNotSupportedException.

        Parameters:
        name - The name of the parameter.
        x - The object containing the input parameter value.
        targetSqlType - The SQL type to be sent to the database.
        Throws:
        java.sql.SQLException - if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement
        java.sql.SQLFeatureNotSupportedException - if the JDBC driver does not support the specified targetSqlType
        NamedParameterException - if the parameter does not exist.
        See Also:
        JDBCType, SQLType
      • close

        public void close()
                   throws java.sql.SQLException
        Closes the statement.
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.sql.SQLException - If there is an SQL exception during close.