Class InsertBuilder


  • public class InsertBuilder
    extends SQLBuilder
    A builder class for creating an INSERT sql statement to add a row to a table.
    Since:
    1.4.0
    • Constructor Detail

      • InsertBuilder

        public InsertBuilder()
    • Method Detail

      • INSERT_INTO

        public InsertBuilder INSERT_INTO​(java.lang.String tableName,
                                         java.lang.String... columnNames)
        Generates sql code to insert a row into a table.
        Parameters:
        tableName - the name of the table
        columnNames - the name of the columns
        Returns:
        the instance of the builder to continue building
        Throws:
        java.lang.IllegalStateException - if this is not the first method called
      • VALUES

        public InsertBuilder VALUES​(java.lang.String... values)
        Finishes the INSERT statement specifying the values to insert. The order of the VALUES statements must match the column order in the INSERT statement.
        Parameters:
        values - the values to insert into the new row
        Returns:
        the instance of the builder to continue building
        Throws:
        java.lang.IllegalStateException - if the INSERT_INTO statement is not called first
      • build

        public TypedStatement build​(Database db)
                             throws java.sql.SQLException
        Runs buildPreparedStatement and passes this object to a new instance of TypedStatement.
        Specified by:
        build in class SQLBuilder
        Parameters:
        db - the database to request the PreparedStatement object from
        Returns:
        a new instance of TypedStatement
        Throws:
        java.sql.SQLException - if a database access error occurs
      • buildAndInsert

        public int buildAndInsert​(Database db)
                           throws java.sql.SQLException
        Runs buildPreparedStatement, executes the statement and returns the number of rows updated.
        Parameters:
        db - the database to request the PreparedStatement object from
        Returns:
        the result of the statement as the number of rows updated
        Throws:
        java.sql.SQLException - if a database access error occurs