Class MonetDBEmbeddedPreparedStatement

java.lang.Object
nl.cwi.monetdb.embedded.env.AbstractConnectionResult
nl.cwi.monetdb.embedded.env.MonetDBEmbeddedPreparedStatement
All Implemented Interfaces:
Closeable, AutoCloseable

public final class MonetDBEmbeddedPreparedStatement
extends AbstractConnectionResult
A prepared statement result set. The user should replace the respective inputs.
Author:
Pedro Ferreira
  • Method Summary

    Modifier and Type Method Description
    void clearParameters()
    Clears the current parameter values immediately.
    void close()
    Close the result set.
    protected void closeResultImplementation()
    Close the result set internally.
    boolean execute()
    Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.
    void executeAndIgnore()
    Like the previous one, but without returning any result.
    QueryResultSet executeQuery()
    Executes the SQL query in this PreparedStatement object and returns QueryResultSet ResultSet object generated by the query.
    int executeUpdate()
    Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.
    void getColumnDigits​(int[] input)
    Gets the column digits as an integer array.
    void getColumnNames​(String[] input)
    Gets the columns names as a string array.
    void getColumnScales​(int[] input)
    Gets the column scales as an integer array.
    void getColumnTypes​(String[] input)
    Gets the columns types as a string array.
    void getMappings​(MonetDBToJavaMapping[] input)
    Gets the Java mappings as a MonetDBToJavaMapping array.
    ResultSetMetaData getMetaData()
    Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed.
    int getNumberOfColumns()
    Returns the number of columns in the result set.
    int getNumberOfRows()
    Returns the number of rows in the result set.
    ParameterMetaData getParameterMetaData()
    Retrieves the number, types and properties of this PreparedStatement object's parameters.
    boolean isPreparedStatementClosed()
    Tells if the prepared statement was closed or not
    void setBigDecimal​(int idx, BigDecimal x)
    Sets the designated parameter to the given java.math.BigDecimal value.
    void setBlob​(int parameterIndex, Blob x)
    Sets the designated parameter to the given Blob object.
    void setBoolean​(int parameterIndex, boolean x)
    Sets the designated parameter to the given Java boolean value.
    void setByte​(int parameterIndex, byte x)
    Sets the designated parameter to the given Java byte value.
    void setBytes​(int parameterIndex, byte[] x)
    Sets the designated parameter to the given Java array of bytes.
    void setClob​(int i, Clob x)
    Sets the designated parameter to the given Clob object.
    void setDate​(int parameterIndex, Date x)
    Sets the designated parameter to the given java.sql.Date value.
    void setDate​(int parameterIndex, Date x, Calendar cal)
    Sets the designated parameter to the given java.sql.Date value, using the given Calendar object.
    void setDouble​(int parameterIndex, double x)
    Sets the designated parameter to the given Java double value.
    void setFloat​(int parameterIndex, float x)
    Sets the designated parameter to the given Java float value.
    void setInt​(int parameterIndex, int x)
    Sets the designated parameter to the given Java int value.
    void setLong​(int parameterIndex, long x)
    Sets the designated parameter to the given Java long value.
    void setNull​(int parameterIndex, int sqlType)
    Sets the designated parameter to SQL NULL.
    void setNull​(int paramIndex, int sqlType, String typeName)
    Sets the designated parameter to SQL NULL.
    void setObject​(int index, Object x)
    Sets the value of the designated parameter using the given object.
    void setObject​(int parameterIndex, Object x, int targetSqlType)
    Sets the value of the designated parameter with the given object.
    void setObject​(int parameterIndex, Object x, int targetSqlType, int scale)
    Sets the value of the designated parameter with the given object.
    void setShort​(int parameterIndex, short x)
    Sets the designated parameter to the given Java short value.
    void setString​(int parameterIndex, String x)
    Sets the designated parameter to the given Java String value.
    void setTime​(int index, Time x)
    Sets the designated parameter to the given java.sql.Time value.
    void setTime​(int index, Time x, Calendar cal)
    Sets the designated parameter to the given java.sql.Time value, using the given Calendar object.
    void setTimestamp​(int index, Timestamp x)
    Sets the designated parameter to the given java.sql.Timestamp value.
    void setTimestamp​(int index, Timestamp x, Calendar cal)
    Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object.
    void setURL​(int parameterIndex, URL x)
    Sets the designated parameter to the given java.net.URL value.

    Methods inherited from class nl.cwi.monetdb.embedded.env.AbstractConnectionResult

    checkMetadataArrayLength, getConnection, getRandomIdentifier

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getNumberOfColumns

      public int getNumberOfColumns()
      Description copied from class: AbstractConnectionResult
      Returns the number of columns in the result set.
      Specified by:
      getNumberOfColumns in class AbstractConnectionResult
      Returns:
      Number of columns
    • getNumberOfRows

      public int getNumberOfRows()
      Description copied from class: AbstractConnectionResult
      Returns the number of rows in the result set.
      Specified by:
      getNumberOfRows in class AbstractConnectionResult
      Returns:
      Number of rows
    • getColumnNames

      public void getColumnNames​(String[] input) throws MonetDBEmbeddedException
      Description copied from class: AbstractConnectionResult
      Gets the columns names as a string array.
      Specified by:
      getColumnNames in class AbstractConnectionResult
      Parameters:
      input - The columns names array to fill.
      Throws:
      MonetDBEmbeddedException - If an error in the database occurred.
    • getColumnTypes

      public void getColumnTypes​(String[] input) throws MonetDBEmbeddedException
      Description copied from class: AbstractConnectionResult
      Gets the columns types as a string array.
      Specified by:
      getColumnTypes in class AbstractConnectionResult
      Parameters:
      input - The columns types array to fill.
      Throws:
      MonetDBEmbeddedException - If an error in the database occurred.
    • getMappings

      public void getMappings​(MonetDBToJavaMapping[] input) throws MonetDBEmbeddedException
      Description copied from class: AbstractConnectionResult
      Gets the Java mappings as a MonetDBToJavaMapping array.
      Specified by:
      getMappings in class AbstractConnectionResult
      Parameters:
      input - The columns mappings array to fill.
      Throws:
      MonetDBEmbeddedException - If an error in the database occurred..
    • getColumnDigits

      public void getColumnDigits​(int[] input) throws MonetDBEmbeddedException
      Description copied from class: AbstractConnectionResult
      Gets the column digits as an integer array.
      Specified by:
      getColumnDigits in class AbstractConnectionResult
      Parameters:
      input - The columns digits array to fill.
      Throws:
      MonetDBEmbeddedException - If an error in the database occurred.
    • getColumnScales

      public void getColumnScales​(int[] input) throws MonetDBEmbeddedException
      Description copied from class: AbstractConnectionResult
      Gets the column scales as an integer array.
      Specified by:
      getColumnScales in class AbstractConnectionResult
      Parameters:
      input - The columns scales array to fill.
      Throws:
      MonetDBEmbeddedException - If an error in the database occurred.
    • isPreparedStatementClosed

      public boolean isPreparedStatementClosed()
      Tells if the prepared statement was closed or not
      Returns:
      A boolean indicating if the prepared statement has been closed or not
    • clearParameters

      public void clearParameters()
      Clears the current parameter values immediately.
    • execute

      public boolean execute() throws MonetDBEmbeddedException
      Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement. Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by the methods executeQuery and executeUpdate.
      Returns:
      true if the first result is a ResultSet object; false if the first result is an update count or there is no result
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • executeAndIgnore

      public void executeAndIgnore() throws MonetDBEmbeddedException
      Like the previous one, but without returning any result.
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • executeQuery

      public QueryResultSet executeQuery() throws MonetDBEmbeddedException
      Executes the SQL query in this PreparedStatement object and returns QueryResultSet ResultSet object generated by the query.
      Returns:
      a QueryResultSet object that contains the data produced by the query never null
      Throws:
      MonetDBEmbeddedException - if a database access error occurs or the SQL statement does not return a QueryResultSet
    • executeUpdate

      public int executeUpdate() throws MonetDBEmbeddedException
      Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.
      Returns:
      either (1) the row count for INSERT, UPDATE, or DELETE statements or (2) 0 for SQL statements that return nothing
      Throws:
      MonetDBEmbeddedException - if a database access error occurs or the SQL statement returns a ResultSet
    • setNull

      public void setNull​(int parameterIndex, int sqlType) throws MonetDBEmbeddedException
      Sets the designated parameter to SQL NULL. Note: You must specify the parameter's SQL type.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      sqlType - the SQL type code defined in java.sql.Types
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setNull

      public void setNull​(int paramIndex, int sqlType, String typeName) throws MonetDBEmbeddedException
      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:
      paramIndex - the first parameter is 1, the second is 2, ...
      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:
      MonetDBEmbeddedException - if a database access error occurs
    • setBigDecimal

      public void setBigDecimal​(int idx, BigDecimal x) throws MonetDBEmbeddedException
      Sets the designated parameter to the given java.math.BigDecimal value.
      Parameters:
      idx - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setBlob

      public void setBlob​(int parameterIndex, Blob x) throws MonetDBEmbeddedException
      Sets the designated parameter to the given Blob object. The driver converts this to an SQL BLOB value when it sends it to the database.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - a Blob object that maps an SQL BLOB value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setBoolean

      public void setBoolean​(int parameterIndex, boolean x) throws MonetDBEmbeddedException
      Sets the designated parameter to the given Java boolean value. The driver converts this to an SQL BOOLEAN value when it sends it to the database.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setByte

      public void setByte​(int parameterIndex, byte x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setBytes

      public void setBytes​(int parameterIndex, byte[] x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setClob

      public void setClob​(int i, Clob x) throws MonetDBEmbeddedException
      Sets the designated parameter to the given Clob object. The driver converts this to an SQL CLOB value when it sends it to the database.
      Parameters:
      i - the first parameter is 1, the second is 2, ...
      x - a Clob object that maps an SQL CLOB value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setDate

      public void setDate​(int parameterIndex, Date x) throws MonetDBEmbeddedException
      Sets the designated parameter to the given java.sql.Date value. The driver converts this to an SQL DATE value when it sends it to the database.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setDate

      public void setDate​(int parameterIndex, Date x, Calendar cal) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      cal - the Calendar object the driver will use to construct the date
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setDouble

      public void setDouble​(int parameterIndex, double x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setFloat

      public void setFloat​(int parameterIndex, float x) throws MonetDBEmbeddedException
      Sets the designated parameter to the given Java float value. The driver converts this to an SQL FLOAT value when it sends it to the database.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setInt

      public void setInt​(int parameterIndex, int x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setLong

      public void setLong​(int parameterIndex, long x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setObject

      public void setObject​(int index, Object x) throws MonetDBEmbeddedException
      Sets the value of the designated parameter using the given object. The second parameter must be of type Object; therefore, the java.lang equivalent objects should be used for built-in types. 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:
      index - the first parameter is 1, the second is 2, ...
      x - the object containing the input parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs or the type of the given object is ambiguous
    • setObject

      public void setObject​(int parameterIndex, Object x, int targetSqlType) throws MonetDBEmbeddedException
      Sets the value of the designated parameter with the given object. This method is like the method setObject below, except that it assumes a scale of zero.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the object containing the input parameter value
      targetSqlType - the Java ordinal value from MonetDBToJavaMapping
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setObject

      public void setObject​(int parameterIndex, Object x, int targetSqlType, int scale) throws MonetDBEmbeddedException
      Sets the value of the designated parameter with the given object. The second argument must be an object type; for integral values, the java.lang equivalent objects should be used. Note that this method may be used to pass database-specific abstract data types. To meet the requirements of this interface, the Java object is converted in the driver, instead of using a SQL CAST construct.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the object containing the input parameter value
      targetSqlType - the Java ordinal value from MonetDBToJavaMapping
      scale - 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:
      MonetDBEmbeddedException - if a database access error occurs
      See Also:
      Types
    • setShort

      public void setShort​(int parameterIndex, short x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setString

      public void setString​(int parameterIndex, String x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setTime

      public void setTime​(int index, Time x) throws MonetDBEmbeddedException
      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:
      index - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setTime

      public void setTime​(int index, Time x, Calendar cal) throws MonetDBEmbeddedException
      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:
      index - the first parameter is 1, the second is 2, ...
      x - the parameter value
      cal - the Calendar object the driver will use to construct the time
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setTimestamp

      public void setTimestamp​(int index, Timestamp x) throws MonetDBEmbeddedException
      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:
      index - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setTimestamp

      public void setTimestamp​(int index, Timestamp x, Calendar cal) throws MonetDBEmbeddedException
      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:
      index - the first parameter is 1, the second is 2, ...
      x - the parameter value
      cal - the Calendar object the driver will use to construct the timestamp
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • setURL

      public void setURL​(int parameterIndex, URL x) throws MonetDBEmbeddedException
      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:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the java.net.URL object to be set
      Throws:
      MonetDBEmbeddedException - if a database access error occurs
    • getMetaData

      public ResultSetMetaData getMetaData()
      Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed. Because a PreparedStatement object is precompiled, it is possible to know about the ResultSet object that it will return without having to execute it. Consequently, it is possible to invoke the method getMetaData on a PreparedStatement object rather than waiting to execute it and then invoking the ResultSet.getMetaData method on the ResultSet object that is returned.
      Returns:
      the description of a ResultSet object's columns or null if the driver cannot return a ResultSetMetaData object
    • getParameterMetaData

      public ParameterMetaData getParameterMetaData() throws SQLException
      Retrieves the number, types and properties of this PreparedStatement object's parameters.
      Returns:
      a ParameterMetaData object that contains information about the number, types and properties of this PreparedStatement object's parameters
      Throws:
      SQLException - if a database access error occurs
    • close

      public void close()
      Description copied from class: AbstractConnectionResult
      Close the result set.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AbstractConnectionResult
    • closeResultImplementation

      protected void closeResultImplementation()
      Description copied from class: AbstractConnectionResult
      Close the result set internally.
      Specified by:
      closeResultImplementation in class AbstractConnectionResult