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 Link icon

  • Method Details Link icon

    • getPrepared Link icon

      public PreparedStatement getPrepared()
      Returns:
      PreparedStatement or null if not created.
    • getQuery Link icon

      @Deprecated public StringBuilder getQuery()
      Deprecated.
      Returns:
      current query.
    • addQuery Link icon

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

      public void setQuery(String value)
      Replaces the current query.
      Parameters:
      value -
    • setPos Link icon

      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 Link icon

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

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

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

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

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

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

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

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

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

      public ResultSet executeQuery() throws SQLException
      Executes the prepared statement for select.
      Returns:
      Throws:
      SQLException
    • executeUpdate Link icon

      public int executeUpdate() throws SQLException
      Executes the prepared statement for update.
      Returns:
      Throws:
      SQLException
    • executeInsert Link icon

      public int executeInsert() throws SQLException
      Executes the prepared insert statement.
      Returns:
      generated ID.
      Throws:
      SQLException
    • close Link icon

      public void close()
      Specified by:
      close in interface AutoCloseable
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object