SimpleJdbcInsert is a multi-threaded, reusable object providing easy
(batch) insert capabilities for a table. It provides meta-data processing to
simplify the code needed to construct a basic insert statement. All you need
to provide is the name of the table and a Map containing the column
names and the column values.
The meta-data processing is based on the DatabaseMetaData provided
by the JDBC driver. As long as the JDBC driver can provide the names of the columns
for a specified table then we can rely on this auto-detection feature. If that
is not the case, then the column names must be specified explicitly.
The actual (batch) insert is handled using Spring's JdbcTemplate.
Many of the configuration methods return the current instance of the
SimpleJdbcInsert to provide the ability to chain multiple ones together
in a "fluent" API style.
java.sql.DatabaseMetaData , org.springframework.jdbc.core.JdbcTemplate
| Access | Constructor and Description |
|---|---|
| public | SimpleJdbcInsert(DataSource
the dataSource)DataSource to useConstructor that accepts the JDBC |
| public | SimpleJdbcInsert(JdbcTemplate
the jdbcTemplate)JdbcTemplate to useAlternative constructor that accepts the |
| Modifier and Type | Method and Description |
|---|---|
| public int | execute(Map<String, ?>
a Map containing column names and corresponding value args)Implements org. |
| public int | execute(SqlParameterSource
the SqlParameterSource containing values to use for insert parameterSource)Implements org. |
| public Number | executeAndReturnKey(Map<String, ?>
a Map containing column names and corresponding value args)Implements org. |
| public Number | executeAndReturnKey(SqlParameterSource
the SqlParameterSource containing values to use for insert parameterSource)Implements org. |
| public KeyHolder | executeAndReturnKeyHolder(Map<String, ?>
a Map containing column names and corresponding value args)Implements org. |
| public KeyHolder | executeAndReturnKeyHolder(SqlParameterSource
the SqlParameterSource containing values to use for insert parameterSource)Implements org. |
| public int[] | executeBatch(Map<String, ?>...
an array of Maps containing a batch of column names and corresponding value batch)Implements org. |
| public int[] | executeBatch(SqlParameterSource...
an array of SqlParameterSource containing values for the batch batch)Implements org. |
| public SimpleJdbcInsert | includeSynonymsForTableColumnMetaData()
Implements org. |
| public SimpleJdbcInsert | usingColumns(String...
one or more column names columnNames)Implements org. |
| public SimpleJdbcInsert | usingGeneratedKeyColumns(String...
one or more column names columnNames)Implements org. |
| public SimpleJdbcInsert | usingQuotedIdentifiers()
Implements org. |
| public SimpleJdbcInsert | withCatalogName(String
the name of the catalog catalogName)Implements org. |
| public SimpleJdbcInsert | withoutTableColumnMetaDataAccess()
Implements org. |
| public SimpleJdbcInsert | withSchemaName(String
the name of the schema schemaName)Implements org. |
| public SimpleJdbcInsert | withTableName(String
the name of the stored table tableName)Implements org. |
| SimpleJdbcInsert | back to summary |
|---|---|
| public SimpleJdbcInsert(DataSource dataSource) Constructor that accepts the JDBC
| |
| SimpleJdbcInsert | back to summary |
|---|---|
| public SimpleJdbcInsert(JdbcTemplate jdbcTemplate) Alternative constructor that accepts the
| |
| execute | back to summary |
|---|---|
| public int execute(Map<String, ?> args) Implements org. Doc from org. Execute the insert using the values passed in. | |
| execute | back to summary |
|---|---|
| public int execute(SqlParameterSource parameterSource) Implements org. Doc from org. Execute the insert using the values passed in.
| |
| executeAndReturnKey | back to summary |
|---|---|
| public Number executeAndReturnKey(Map<String, ?> args) Implements org. Doc from org. Execute the insert using the values passed in and return the generated key. This requires that the name of the columns with auto generated keys have been specified. This method will always return a KeyHolder but the caller must verify that it actually contains the generated keys. | |
| executeAndReturnKey | back to summary |
|---|---|
| public Number executeAndReturnKey(SqlParameterSource parameterSource) Implements org. Doc from org. Execute the insert using the values passed in and return the generated key. This requires that the name of the columns with auto generated keys have been specified. This method will always return a KeyHolder but the caller must verify that it actually contains the generated keys.
| |
| executeAndReturnKeyHolder | back to summary |
|---|---|
| public KeyHolder executeAndReturnKeyHolder(Map<String, ?> args) Implements org. Doc from org. Execute the insert using the values passed in and return the generated keys. This requires that the name of the columns with auto generated keys have been specified. This method will always return a KeyHolder but the caller must verify that it actually contains the generated keys. | |
| executeAndReturnKeyHolder | back to summary |
|---|---|
| public KeyHolder executeAndReturnKeyHolder(SqlParameterSource parameterSource) Implements org. Doc from org. Execute the insert using the values passed in and return the generated keys. This requires that the name of the columns with auto generated keys have been specified. This method will always return a KeyHolder but the caller must verify that it actually contains the generated keys.
| |
| executeBatch | back to summary |
|---|---|
| public int[] executeBatch(Map<String, ?>... batch) Implements org. Doc from org. Execute a batch insert using the batch of values passed in.
| |
| executeBatch | back to summary |
|---|---|
| public int[] executeBatch(SqlParameterSource... batch) Implements org. Doc from org. Execute a batch insert using the batch of values passed in.
| |
| includeSynonymsForTableColumnMetaData | back to summary |
|---|---|
| public SimpleJdbcInsert includeSynonymsForTableColumnMetaData() Implements org. Include synonyms for the column meta-data lookups via JDBC. Note This is only necessary to include for Oracle since other databases supporting synonyms seem to include the synonyms automatically.
| |
| usingColumns | back to summary |
|---|---|
| public SimpleJdbcInsert usingColumns(String... columnNames) Implements org. Doc from org. Specify the column names that the insert statement should be limited to use.
| |
| usingGeneratedKeyColumns | back to summary |
|---|---|
| public SimpleJdbcInsert usingGeneratedKeyColumns(String... columnNames) Implements org. Doc from org. Specify the names of any columns that have auto-generated keys.
| |
| usingQuotedIdentifiers | back to summary |
|---|---|
| public SimpleJdbcInsert usingQuotedIdentifiers() Implements org. Doc from org. Specify that SQL identifiers should be quoted. If this method is invoked, the identifier quote string for the underlying database will be used to quote SQL identifiers in generated SQL statements. In this context, SQL identifiers refer to schema, table, and column names. When identifiers are quoted, explicit column names must be supplied via
| |
| withCatalogName | back to summary |
|---|---|
| public SimpleJdbcInsert withCatalogName(String catalogName) Implements org. Doc from org. Specify the catalog name, if any, to be used for the insert.
| |
| withoutTableColumnMetaDataAccess | back to summary |
|---|---|
| public SimpleJdbcInsert withoutTableColumnMetaDataAccess() Implements org. Doc from org. Turn off any processing of column meta-data information obtained via JDBC.
| |
| withSchemaName | back to summary |
|---|---|
| public SimpleJdbcInsert withSchemaName(String schemaName) Implements org. Doc from org. Specify the schema name, if any, to be used for the insert.
| |
| withTableName | back to summary |
|---|---|
| public SimpleJdbcInsert withTableName(String tableName) Implements org. Doc from org. Specify the table name to be used for the insert.
| |