Class: PreparedStatement

$.db. PreparedStatement

$.db.PreparedStatement represents a prepared SQL statement

new PreparedStatement()

Represents a prepared SQL statement

Methods

addBatch()

Adds last parameter values and iterates to the next batch slot
Throws:
  • Throws an error if setBatchSize has not been called successfully or if the object the method is being called on is not valid.

close()

Closes the statement
Throws:
  • Throws an error if the object the method is being called on is not valid.

execute() → {boolean}

Executes a common statement
Throws:
  • Throws an error if the object the method is being called on is not valid.
Returns:
True if the execution yielded a result set (e.g. if a SELECT statement was executed), false if not
Type
boolean

executeBatch() → {array}

Executes a batch insertion. Use setBatchSize and addBatch to prepare for batch execution.
Throws:
  • Throws an error if the object the method is being called on is not valid.
Returns:
Array with integers representing the number of updated rows per batch
Type
array

executeQuery() → {$.db.ResultSet}

Executes an SQL statement
Throws:
  • Throws an error if the object the method is being called on is not valid.
Returns:
ResultSet Holds the result of the executed SQL statement
Type
$.db.ResultSet

executeUpdate() → {integer}

Executes an update statement
Throws:
  • Throws an error if the object the method is being called on is not valid.
Returns:
The number of changed rows resulting from the update statement
Type
integer

getMetaData() → {$.db.ResultSetMetaData}

Returns the metadata of the ResultSet
Deprecated:
  • Use getMetaData on ResultSet.
    See:
    Returns:
    ResultSetMetaData object
    Type
    $.db.ResultSetMetaData

    getMoreResults() → {boolean}

    Checks if more result sets are available and prepares the next result set for retrieval
    Throws:
    • Throws an error if the object the method is being called on is not valid.
    Returns:
    True if the next result set is available
    Type
    boolean

    getParameterMetaData() → {$.db.ParameterMetaData}

    Returns the metadata of the prepared statement
    Throws:
    • Throws an error if the object the method is being called on is not valid.
    Returns:
    ParameterMetaData object
    Type
    $.db.ParameterMetaData

    getResultSet() → {$.db.ResultSet}

    Returns a result set representing a table output parameter
    Throws:
    • Throws an error if the object the method is being called on is not valid.
    Returns:
    ResultSet of the next output table parameter
    Type
    $.db.ResultSet

    getSQLWarning() → {Object|null}

    Returns the warning of the most recently executed statement.
    Throws:
    Throws an error if the object the method is being called on is not valid.
    Returns:
    The return value has two properties: 'code' and 'message'. 'null' is returned if the most recent statement didn't issue a warning.
    Type
    Object | null

    isClosed() → {boolean}

    Checks if the statement is closed.
    Throws:
    • Throws an error if the object the method is being called on is not valid.
    Returns:
    Returns true if the statement is already closed, false if not
    Type
    boolean

    setBatchSize(size)

    Reserves space for batch insertion
    Parameters:
    Name Type Description
    size integer The number (count) of batch insertions that will be performed
    Throws:
    • Throws an error on invalid parameters or if the object the method is being called on is not valid.

    setBigInt(columnIndex, value)

    Sets an integer parameter used for BIGINT column types
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value integer The number value to be set for this parameter
    Throws:

    setBlob(columnIndex, value)

    setBlob is used to specify the values for CHAR, VARCHAR, NCHAR, NVARCHAR, BINARY, and VARBINARY column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement, starting from 1
    value ArrayBuffer The ArrayBuffer object to be set for this parameter, can also be an Array of integers or a string.
    Throws:

    setBString(columnIndex, value)

    Sets an array buffer parameter used for BINARY, VARBINARY column types.
    Remark: the BINARY type is deprecated - its behavior in row store and column store differs in that row store may pad with zeros.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value ArrayBuffer The ArrayBuffer object to be set for this parameter.
    Throws:

    setClob(columnIndex, value)

    setClob is used to specify the values for CLOB column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value string The string value to be set for this parameter
    Throws:

    setDate(columnIndex, value, format)

    Sets a Date parameter for DATE columns, but works with TIME and TIMESTAMP. It is not possible to set the time with setDate; you can only set the date.
    Parameters:
    Name Type Argument Default Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value Date | string The date to be set for this parameter
    The parameter can be either a Date object, a string in default ptime format (YYYY-MM-DD), or a string in the optionally specified format.
    For example: 'yyyymmdd' or 'yyyy-mm-dd' or 'yyyy/mm/dd'
    • Y,YY,YYY,YYYY-year
    • D-day
    • J-Julian day
    • MONTH-by name,MON-abbr.
    • M-month
    • Q-quarter
    • RM-Roman numeral month
    • W-week of month
    • WW-week of year.
    Note that when you construct a new Date JavaScript object, the month number starts from 0 (not 1).
    For example the following statement represents 1st of Jan, 2010:
    new Date(2010,0,1);
    format string <optional>
    "" One of the following formats:
    Throws:

    setDecimal(index, value)

    setDecimal sets a decimal parameter used for DECIMAL column types.
    Parameters:
    Name Type Description
    index integer The index of the parameter in the prepared statement starting from 1
    value number The number value to be set for this parameter
    Throws:

    setDouble(columnIndex, value)

    setDouble sets a double parameter used for FLOAT and DOUBLE column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value number The number value to be set for this parameter
    Throws:

    setFloat(columnIndex, value)

    setFloat sets a float parameter used for FLOAT column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value number The number value to be set for this parameter
    Throws:

    setInteger(columnIndex, value)

    Sets an integer parameter used for TINYINT, SMALLINT, INT column types
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value integer The integer value to be set for this parameter
    Throws:

    setNClob(columnIndex, value)

    setNClob is used to specify the values for NCLOB column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value string The string value to be set for this parameter
    Throws:

    setNString(columnIndex, value)

    Sets a string parameter used for NCHAR, NVARCHAR parameter types, which should be used for strings containing Unicode characters.
    This function converts the given Unicode string into a storable format. Make sure you use getNString to read the data. If you use getString on a column you wrote with setNString, an exception is thrown if the string contains Unicode characters larger than 0xFFFF.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter starting from 1
    value string The string value to be set for this parameter
    Throws:

    setNull(columnIndex)

    setNull is used to set a Null parameter used for all column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    Throws:

    setReal(columnIndex, value)

    setReal sets a real parameter used for REAL column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value number The number value to be set for this parameter
    Throws:

    setSmallInt(columnIndex, value)

    Sets an integer parameter used for SMALLINT column types
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value integer The integer value to be set for this parameter
    Throws:

    setString(columnIndex, value)

    Sets a string parameter used for CHAR, VARCHAR column types; ASCII only, not suitable for strings containing Unicode characters
    This function can be used to store strings containing ASCII and a subset of Unicode (namely BMP; the first 0xFFFF characters).
    This function does not convert data; to improve performance, it stores data directly in the database.
    Note that special characters (in Unicode SMP or SIP) can cause the read operation to fail. For more information see Plane (Unicode).
    If also need special Unicode characters or if you are not sure what this means it is safer to use setNString.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the statement starting from 1
    value string The string value to be set for this parameter
    Throws:

    setText(columnIndex, value)

    setText is used to specify the values for TEXT column types.
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value string The string value to be set for this parameter
    Throws:

    setTime(columnIndex, value, format)

    Sets a Time parameter used for TIME column types (hour, min, sec). You cannot set milliseconds (mls).
    Parameters:
    Name Type Argument Default Description
    columnIndex integer The index of the parameter in the prepared statement, starting from 1
    value Date | string The Date value to be set for this parameter
    • HH:MI:SS.FF AM
    • HH24:MI:SS.FF
    • HH:MI:SS AM
    • HH24:MI:SS
    • HH:MI AM
    • HH24:MI
    • HH24:MI:SS.FF Z
    • HH24:MI:SS Z
    format string <optional>
    "" One of the following formats:
    Throws:

    setTimestamp(columnIndex, value, format)

    Sets a Timestamp parameter used for TIMESTAMP column types
    Parameters:
    Name Type Argument Default Description
    columnIndex integer The index of the parameter in the prepared statement starting from 1
    value Date | string The timestamp value to be set for this parameter The default format is: date separator time, for example,
    2001-01-02 01:02:03.123, where date is the format to use for the date value
    (see setDate), separator can be a space, a comma, or the letter T, and
    time is the format to use for the time value (see setTime).
    Examples:
    2001-01-02 01:02:03.123
    2001-01-02,01:02:03.123
    2001-01-02T01:02:03.123
    st.setTimestamp(4,"01.02.2003 01:02:03.123", "DD.MM.YYYY HH:MI:SS.FF");
    format string <optional>
    "" Optional, see also setDate and setTime
    Throws:

    setTinyInt(columnIndex, value)

    Sets an integer parameter used for TINYINT column types
    Parameters:
    Name Type Description
    columnIndex integer The index of the parameter in the prepared statement, starting from 1
    value integer The integer value to be set for this parameter (unsigned char: min 0, max 255)
    Throws: