Package org.bgerp.util.sql

# Class PreparedQuery

java.lang.Object
org.bgerp.util.sql.PreparedQuery

All Implemented Interfaces:
  `AutoCloseable`

Direct Known Subclasses:
  `PreparedDelay`

public class PreparedQuery extends Object implements AutoCloseable
Dynamically builds of `PreparedStatement`. Allows adding params without definition of position number.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PreparedQuery(Connection con)`
  `PreparedQuery(Connection con, String query)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `PreparedQuery`
  `addBigDecimal(BigDecimal value)`
  Adds Decimal parameter in the prepared statement.
  `PreparedQuery`
  `addBoolean(Boolean value)`
  Adds Boolean parameter in the prepared statement.
  `PreparedQuery`
  `addDate(Date value)`
  Adds Date parameter in the prepared statement.
  `PreparedQuery`
  `addInt(int value)`
  Adds int parameter in the prepared statement.
  `PreparedQuery`
  `addLong(long value)`
  Adds long parameter in the prepared statement
  `PreparedQuery`
  `addObjects(Object... values)`
  Adds parameters with arbitrary types in the prepared statement.
  `PreparedQuery`
  `addQuery(String value)`
  Adds SQL string to the query.
  `PreparedQuery`
  `addString(String value)`
  Adds int parameter in the prepared statement.
  `PreparedQuery`
  `addTimestamp(Timestamp value)`
  Adds Timestamp parameter in the prepared statement.
  `PreparedQuery`
  `addTimestamp(Date value)`
  Adds Timestamp parameter in the prepared statement.
  `void`
  `close()`
  `int`
  `executeInsert()`
  Executes the prepared insert statement.
  `ResultSet`
  `executeQuery()`
  Executes the prepared statement for select.
  `int`
  `executeUpdate()`
  Executes the prepared statement for update.
  `PreparedStatement`
  `getPrepared()`
  `StringBuilder`
  `getQuery()`
  Deprecated.
  `void`
  `setPos(int pos)`
  Changes position if the last parameter.
  `void`
  `setQuery(String value)`
  Replaces the current query.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PreparedQuery

    public PreparedQuery(Connection con)

  - ### PreparedQuery

    public PreparedQuery(Connection con, String query)

- ## Method Details

  - ### getPrepared

    public PreparedStatement getPrepared()
    Returns:
      `PreparedStatement` or `null` if not created.

  - ### getQuery

    @Deprecated public StringBuilder getQuery()
    Deprecated.
    Returns:
      current query.

  - ### addQuery

    public PreparedQuery addQuery(String value)
    Adds SQL string to the query.
    Parameters:
      `value` -
    Returns:
      the current object.

  - ### setQuery

    public void setQuery(String value)
    Replaces the current query.
    Parameters:
      `value` -

  - ### setPos

    public void setPos(int pos) throws SQLException
    Changes position if the last parameter. Adding new parameters will be continued after this. Closes existing `PreparedStatement` if exists and assigns it to `null`.
    Parameters:
      `pos` - 1 based position.
    Throws:
      `SQLException`

  - ### addInt

    public PreparedQuery addInt(int value)
    Adds int parameter in the prepared statement.
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addLong

    public PreparedQuery addLong(long value)
    Adds long parameter in the prepared statement
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addBigDecimal

    public PreparedQuery addBigDecimal(BigDecimal value)
    Adds Decimal parameter in the prepared statement.
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addString

    public PreparedQuery addString(String value)
    Adds int parameter in the prepared statement.
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addDate

    public PreparedQuery addDate(Date value)
    Adds Date parameter in the prepared statement.
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addTimestamp

    public PreparedQuery addTimestamp(Timestamp value)
    Adds Timestamp parameter in the prepared statement.
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addTimestamp

    public PreparedQuery addTimestamp(Date value)
    Adds Timestamp parameter in the prepared statement.
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addBoolean

    public PreparedQuery addBoolean(Boolean value)
    Adds Boolean parameter in the prepared statement.
    Parameters:
      `value` -
    Returns:
      the current instance.

  - ### addObjects

    public PreparedQuery addObjects(Object... values)
    Adds parameters with arbitrary types in the prepared statement.
    Parameters:
      `values` -
    Returns:
      the current instance.

  - ### executeQuery

    public ResultSet executeQuery() throws SQLException
    Executes the prepared statement for select.
    Returns:
    Throws:
      `SQLException`

  - ### executeUpdate

    public int executeUpdate() throws SQLException
    Executes the prepared statement for update.
    Returns:
    Throws:
      `SQLException`

  - ### executeInsert

    public int executeInsert() throws SQLException
    Executes the prepared insert statement.
    Returns:
      generated ID.
    Throws:
      `SQLException`

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`