public class InsertBuilder extends SQLBuilder
A builder class for creating an INSERT sql statement to add a row to a table.
Constructor and Description |
---|
InsertBuilder() |
Modifier and Type | Method and Description |
---|---|
TypedStatement |
build(Database db)
Runs buildPreparedStatement and passes this object to a new instance of
TypedStatement . |
int |
buildAndInsert(Database db)
Runs buildPreparedStatement, executes the statement and returns the number of rows updated.
|
InsertBuilder |
INSERT_INTO(String tableName,
String... columnNames)
Generates sql code to insert a row into a table.
|
InsertBuilder |
VALUES(String... values)
Finishes the INSERT statement specifying the values to insert.
|
buildPreparedStatement, getSql, getStatement, setStatement, toString
public InsertBuilder INSERT_INTO(String tableName, String... columnNames)
Generates sql code to insert a row into a table.
tableName
- the name of the tablecolumnNames
- the name of the columnsIllegalStateException
- if this is not the first method calledpublic InsertBuilder VALUES(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.
values
- the values to insert into the new rowIllegalStateException
- if the INSERT_INTO statement is not called firstpublic TypedStatement build(Database db) throws SQLException
Runs buildPreparedStatement and passes this object to a new instance of TypedStatement
.
build
in class SQLBuilder
db
- the database to request the PreparedStatement
object fromTypedStatement
SQLException
- if a database access error occurspublic int buildAndInsert(Database db) throws SQLException
Runs buildPreparedStatement, executes the statement and returns the number of rows updated.
db
- the database to request the PreparedStatement
object fromSQLException
- if a database access error occursCopyright © 2017–2018 J&G CompTech. All rights reserved.