public class

SimpleJdbcInsert

extends AbstractJdbcInsert
implements SimpleJdbcInsertOperations
java.lang.Object
   ↳ org.springframework.jdbc.core.simple.AbstractJdbcInsert
     ↳ org.springframework.jdbc.core.simple.SimpleJdbcInsert

Class Overview

A SimpleJdbcInsert is a multi-threaded, reusable object providing easy 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 JBDC driver can provide the names of the columns for a specified table than 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 being handled using Spring's JdbcTemplate.

Many of the configuration methods return the current instance of the SimpleJdbcInsert to provide the ability to string multiple ones together in a "fluid" interface style.

See Also

Summary

[Expand]
Inherited Fields
From class org.springframework.jdbc.core.simple.AbstractJdbcInsert
Public Constructors
SimpleJdbcInsert(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.
Public Methods
int execute(Map<StringObject> args)
Execute the insert using the values passed in.
int execute(SqlParameterSource parameterSource)
Execute the insert using the values passed in.
Number executeAndReturnKey(SqlParameterSource parameterSource)
Execute the insert using the values passed in and return the generated key.
Number executeAndReturnKey(Map<StringObject> args)
Execute the insert using the values passed in and return the generated key.
KeyHolder executeAndReturnKeyHolder(SqlParameterSource parameterSource)
Execute the insert using the values passed in and return the generated keys.
KeyHolder executeAndReturnKeyHolder(Map<StringObject> args)
Execute the insert using the values passed in and return the generated keys.
int[] executeBatch(SqlParameterSource[] batch)
Execute a batch insert using the batch of values passed in.
int[] executeBatch(Map[]<StringObject> batch)
Execute a batch insert using the batch of values passed in.
SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData()
Include synonyms for the column meta data lookups via JDBC.
SimpleJdbcInsertOperations useNativeJdbcExtractorForMetaData(NativeJdbcExtractor nativeJdbcExtractor)
Use a the provided NativeJdbcExtractor during the column meta data lookups via JDBC.
SimpleJdbcInsert usingColumns(String... columnNames)
Specify the column names that the insert statement should be limited to use.
SimpleJdbcInsert usingGeneratedKeyColumns(String... columnNames)
Specify the name sof any columns that have auto generated keys.
SimpleJdbcInsert withCatalogName(String catalogName)
Specify the catalog name, if any, to be used for the insert.
SimpleJdbcInsert withSchemaName(String schemaName)
Specify the shema name, if any, to be used for the insert.
SimpleJdbcInsert withTableName(String tableName)
Specify the table name to be used for the insert.
SimpleJdbcInsertOperations withoutTableColumnMetaDataAccess()
Turn off any processing of column meta data information obtained via JDBC.
[Expand]
Inherited Methods
From class org.springframework.jdbc.core.simple.AbstractJdbcInsert
From class java.lang.Object
From interface org.springframework.jdbc.core.simple.SimpleJdbcInsertOperations

Public Constructors

public SimpleJdbcInsert (DataSource dataSource)

Constructor that takes one parameter with the JDBC DataSource to use when creating the JdbcTemplate.

Parameters
dataSource the DataSource to use

public SimpleJdbcInsert (JdbcTemplate jdbcTemplate)

Alternative Constructor that takes one parameter with the JdbcTemplate to be used.

Parameters
jdbcTemplate the JdbcTemplate to use

Public Methods

public int execute (Map<StringObject> args)

Execute the insert using the values passed in.

Parameters
args Map containing column names and corresponding value
Returns
  • the number of rows affected as returned by the JDBC driver

public int execute (SqlParameterSource parameterSource)

Execute the insert using the values passed in.

Parameters
parameterSource SqlParameterSource containing values to use for insert
Returns
  • the number of rows affected as returned by the JDBC driver

public Number executeAndReturnKey (SqlParameterSource parameterSource)

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 key or throw an exception if a key was not returned.

Parameters
parameterSource SqlParameterSource containing values to use for insert
Returns
  • the generated key value.

public Number executeAndReturnKey (Map<StringObject> args)

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 key or throw an exception if a key was not returned.

Parameters
args Map containing column names and corresponding value
Returns
  • the generated key value

public KeyHolder executeAndReturnKeyHolder (SqlParameterSource parameterSource)

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.

Parameters
parameterSource SqlParameterSource containing values to use for insert
Returns
  • the KeyHolder containing all generated keys

public KeyHolder executeAndReturnKeyHolder (Map<StringObject> args)

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.

Parameters
args Map containing column names and corresponding value
Returns
  • the KeyHolder containing all generated keys

public int[] executeBatch (SqlParameterSource[] batch)

Execute a batch insert using the batch of values passed in.

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

public int[] executeBatch (Map[]<StringObject> batch)

Execute a batch insert using the batch of values passed in.

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

public SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData ()

Include 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.

Returns
  • the instance of this SimpleJdbcInsert

public SimpleJdbcInsertOperations useNativeJdbcExtractorForMetaData (NativeJdbcExtractor nativeJdbcExtractor)

Use a the provided NativeJdbcExtractor during the column meta data lookups via JDBC. Note: this is only necessary to include when running with a connection pool that wraps the meta data connection and when using a database like Oracle where it is necessary to access the native connection to include synonyms.

Returns
  • the instance of this SimpleJdbcInsert

public SimpleJdbcInsert usingColumns (String... columnNames)

Specify the column names that the insert statement should be limited to use.

Parameters
columnNames one or more column names
Returns
  • the instance of this SimpleJdbcInsert

public SimpleJdbcInsert usingGeneratedKeyColumns (String... columnNames)

Specify the name sof any columns that have auto generated keys.

Parameters
columnNames one or more column names
Returns
  • the instance of this SimpleJdbcInsert

public SimpleJdbcInsert withCatalogName (String catalogName)

Specify the catalog name, if any, to be used for the insert.

Parameters
catalogName the name of the catalog
Returns
  • the instance of this SimpleJdbcInsert

public SimpleJdbcInsert withSchemaName (String schemaName)

Specify the shema name, if any, to be used for the insert.

Parameters
schemaName the name of the schema
Returns
  • the instance of this SimpleJdbcInsert

public SimpleJdbcInsert withTableName (String tableName)

Specify the table name to be used for the insert.

Parameters
tableName the name of the stored table
Returns
  • the instance of this SimpleJdbcInsert

public SimpleJdbcInsertOperations withoutTableColumnMetaDataAccess ()

Turn off any processing of column meta data information obtained via JDBC.

Returns
  • the instance of this SimpleJdbcInsert