Class InsertBuilder
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.builders.SQLBuilder
-
- com.jgcomptech.tools.databasetools.jdbc.builders.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 Summary
Constructors Constructor Description InsertBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypedStatement
build(Database db)
Runs buildPreparedStatement and passes this object to a new instance ofTypedStatement
.int
buildAndInsert(Database db)
Runs buildPreparedStatement, executes the statement and returns the number of rows updated.InsertBuilder
INSERT_INTO(java.lang.String tableName, java.lang.String... columnNames)
Generates sql code to insert a row into a table.InsertBuilder
VALUES(java.lang.String... values)
Finishes the INSERT statement specifying the values to insert.-
Methods inherited from class com.jgcomptech.tools.databasetools.jdbc.builders.SQLBuilder
buildPreparedStatement, getSql, getStatement, setStatement, toString
-
-
-
-
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 tablecolumnNames
- 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 ofTypedStatement
.- Specified by:
build
in classSQLBuilder
- Parameters:
db
- the database to request thePreparedStatement
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 thePreparedStatement
object from- Returns:
- the result of the statement as the number of rows updated
- Throws:
java.sql.SQLException
- if a database access error occurs
-
-