Class SimpleJdbcInsert
- All Implemented Interfaces:
SimpleJdbcInsertOperations
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 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" interface style.
- Since:
- 2.5
- Author:
- Thomas Risberg, Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from class org.springframework.jdbc.core.simple.AbstractJdbcInsert
logger -
Constructor Summary
ConstructorsConstructorDescriptionSimpleJdbcInsert(DataSource dataSource) Constructor that takes one parameter with the JDBC DataSource to use when creating the JdbcTemplate.SimpleJdbcInsert(JdbcTemplate jdbcTemplate) Alternative Constructor that takes one parameter with the JdbcTemplate to be used. -
Method Summary
Modifier and TypeMethodDescriptionintExecute the insert using the values passed in.intexecute(SqlParameterSource parameterSource) Execute the insert using the values passed in.executeAndReturnKey(Map<String, ?> args) Execute the insert using the values passed in and return the generated key.executeAndReturnKey(SqlParameterSource parameterSource) Execute the insert using the values passed in and return the generated key.executeAndReturnKeyHolder(Map<String, ?> args) Execute the insert using the values passed in and return the generated keys.executeAndReturnKeyHolder(SqlParameterSource parameterSource) Execute the insert using the values passed in and return the generated keys.int[]executeBatch(Map<String, ?>... batch) Execute a batch insert using the batch of values passed in.int[]executeBatch(SqlParameterSource... batch) Execute a batch insert using the batch of values passed in.Include synonyms for the column meta-data lookups via JDBC.usingColumns(String... columnNames) Specify the column names that the insert statement should be limited to use.usingGeneratedKeyColumns(String... columnNames) Specify the names of any columns that have auto generated keys.withCatalogName(String catalogName) Specify the catalog name, if any, to be used for the insert.Turn off any processing of column meta-data information obtained via JDBC.withSchemaName(String schemaName) Specify the schema name, if any, to be used for the insert.withTableName(String tableName) Specify the table name to be used for the insert.Methods inherited from class org.springframework.jdbc.core.simple.AbstractJdbcInsert
checkCompiled, checkIfConfigurationModificationIsAllowed, compile, compileInternal, doExecute, doExecute, doExecuteAndReturnKey, doExecuteAndReturnKey, doExecuteAndReturnKeyHolder, doExecuteAndReturnKeyHolder, doExecuteBatch, doExecuteBatch, getCatalogName, getColumnNames, getGeneratedKeyNames, getInsertString, getInsertTypes, getJdbcTemplate, getSchemaName, getTableName, isCompiled, matchInParameterValuesWithInsertColumns, matchInParameterValuesWithInsertColumns, onCompileInternal, setAccessTableColumnMetaData, setCatalogName, setColumnNames, setGeneratedKeyName, setGeneratedKeyNames, setOverrideIncludeSynonymsDefault, setSchemaName, setTableName
-
Constructor Details
-
SimpleJdbcInsert
Constructor that takes one parameter with the JDBC DataSource to use when creating the JdbcTemplate.- Parameters:
dataSource- theDataSourceto use- See Also:
-
SimpleJdbcInsert
Alternative Constructor that takes one parameter with the JdbcTemplate to be used.- Parameters:
jdbcTemplate- theJdbcTemplateto use- See Also:
-
-
Method Details
-
withTableName
Description copied from interface:SimpleJdbcInsertOperationsSpecify the table name to be used for the insert.- Specified by:
withTableNamein interfaceSimpleJdbcInsertOperations- Parameters:
tableName- the name of the stored table- Returns:
- the instance of this SimpleJdbcInsert
-
withSchemaName
Description copied from interface:SimpleJdbcInsertOperationsSpecify the schema name, if any, to be used for the insert.- Specified by:
withSchemaNamein interfaceSimpleJdbcInsertOperations- Parameters:
schemaName- the name of the schema- Returns:
- the instance of this SimpleJdbcInsert
-
withCatalogName
Description copied from interface:SimpleJdbcInsertOperationsSpecify the catalog name, if any, to be used for the insert.- Specified by:
withCatalogNamein interfaceSimpleJdbcInsertOperations- Parameters:
catalogName- the name of the catalog- Returns:
- the instance of this SimpleJdbcInsert
-
usingColumns
Description copied from interface:SimpleJdbcInsertOperationsSpecify the column names that the insert statement should be limited to use.- Specified by:
usingColumnsin interfaceSimpleJdbcInsertOperations- Parameters:
columnNames- one or more column names- Returns:
- the instance of this SimpleJdbcInsert
-
usingGeneratedKeyColumns
Description copied from interface:SimpleJdbcInsertOperationsSpecify the names of any columns that have auto generated keys.- Specified by:
usingGeneratedKeyColumnsin interfaceSimpleJdbcInsertOperations- Parameters:
columnNames- one or more column names- Returns:
- the instance of this SimpleJdbcInsert
-
withoutTableColumnMetaDataAccess
Description copied from interface:SimpleJdbcInsertOperationsTurn off any processing of column meta-data information obtained via JDBC.- Specified by:
withoutTableColumnMetaDataAccessin interfaceSimpleJdbcInsertOperations- Returns:
- the instance of this SimpleJdbcInsert
-
includeSynonymsForTableColumnMetaData
Description copied from interface:SimpleJdbcInsertOperationsInclude synonyms for the column meta-data lookups via JDBC.Note: This is only necessary to include for Oracle since other databases supporting synonyms seems to include the synonyms automatically.
- Specified by:
includeSynonymsForTableColumnMetaDatain interfaceSimpleJdbcInsertOperations- Returns:
- the instance of this SimpleJdbcInsert
-
execute
Description copied from interface:SimpleJdbcInsertOperationsExecute the insert using the values passed in.- Specified by:
executein interfaceSimpleJdbcInsertOperations- Parameters:
args- a Map containing column names and corresponding value- Returns:
- the number of rows affected as returned by the JDBC driver
-
execute
Description copied from interface:SimpleJdbcInsertOperationsExecute the insert using the values passed in.- Specified by:
executein interfaceSimpleJdbcInsertOperations- Parameters:
parameterSource- the SqlParameterSource containing values to use for insert- Returns:
- the number of rows affected as returned by the JDBC driver
-
executeAndReturnKey
Description copied from interface:SimpleJdbcInsertOperationsExecute 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.
- Specified by:
executeAndReturnKeyin interfaceSimpleJdbcInsertOperations- Parameters:
args- a Map containing column names and corresponding value- Returns:
- the generated key value
-
executeAndReturnKey
Description copied from interface:SimpleJdbcInsertOperationsExecute 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.
- Specified by:
executeAndReturnKeyin interfaceSimpleJdbcInsertOperations- Parameters:
parameterSource- the SqlParameterSource containing values to use for insert- Returns:
- the generated key value.
-
executeAndReturnKeyHolder
Description copied from interface:SimpleJdbcInsertOperationsExecute 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.
- Specified by:
executeAndReturnKeyHolderin interfaceSimpleJdbcInsertOperations- Parameters:
args- a Map containing column names and corresponding value- Returns:
- the KeyHolder containing all generated keys
-
executeAndReturnKeyHolder
Description copied from interface:SimpleJdbcInsertOperationsExecute 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.
- Specified by:
executeAndReturnKeyHolderin interfaceSimpleJdbcInsertOperations- Parameters:
parameterSource- the SqlParameterSource containing values to use for insert- Returns:
- the KeyHolder containing all generated keys
-
executeBatch
Description copied from interface:SimpleJdbcInsertOperationsExecute a batch insert using the batch of values passed in.- Specified by:
executeBatchin interfaceSimpleJdbcInsertOperations- Parameters:
batch- an array of Maps containing a batch of column names and corresponding value- Returns:
- the array of number of rows affected as returned by the JDBC driver
-
executeBatch
Description copied from interface:SimpleJdbcInsertOperationsExecute a batch insert using the batch of values passed in.- Specified by:
executeBatchin interfaceSimpleJdbcInsertOperations- Parameters:
batch- an array of SqlParameterSource containing values for the batch- Returns:
- the array of number of rows affected as returned by the JDBC driver
-