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 Details

  • 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