类 SimpleJdbcInsert
- java.lang.Object
- org.springframework.jdbc.core.simple.AbstractJdbcInsert
- org.springframework.jdbc.core.simple.SimpleJdbcInsert
- 所有已实现的接口:
SimpleJdbcInsertOperations
public class SimpleJdbcInsert extends AbstractJdbcInsert implements SimpleJdbcInsertOperations
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 JDBC 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 chain multiple ones together in a "fluent" interface style.
- 从以下版本开始:
- 2.5
- 作者:
- Thomas Risberg, Juergen Hoeller
- 另请参阅:
DatabaseMetaData
,JdbcTemplate
字段概要
从类继承的字段 org.springframework.jdbc.core.simple.AbstractJdbcInsert
logger
构造器概要
构造器 构造器 说明 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.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 int
execute(Map<String,?> args)
Execute the insert using the values passed in.int
execute(SqlParameterSource parameterSource)
Execute the insert using the values passed in.Number
executeAndReturnKey(Map<String,?> args)
Execute the insert using the values passed in and return the generated key.Number
executeAndReturnKey(SqlParameterSource parameterSource)
Execute the insert using the values passed in and return the generated key.KeyHolder
executeAndReturnKeyHolder(Map<String,?> args)
Execute the insert using the values passed in and return the generated keys.KeyHolder
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.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 names of any columns that have auto generated keys.SimpleJdbcInsert
withCatalogName(String catalogName)
Specify the catalog name, if any, to be used for the insert.SimpleJdbcInsertOperations
withoutTableColumnMetaDataAccess()
Turn off any processing of column meta-data information obtained via JDBC.SimpleJdbcInsert
withSchemaName(String schemaName)
Specify the schema name, if any, to be used for the insert.SimpleJdbcInsert
withTableName(String tableName)
Specify the table name to be used for the insert.从类继承的方法 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, setNativeJdbcExtractor, setOverrideIncludeSynonymsDefault, setSchemaName, setTableName
构造器详细资料
SimpleJdbcInsert
public SimpleJdbcInsert(DataSource dataSource)
Constructor that takes one parameter with the JDBC DataSource to use when creating the JdbcTemplate.- 参数:
dataSource
- theDataSource
to use- 另请参阅:
JdbcAccessor.setDataSource(javax.sql.DataSource)
SimpleJdbcInsert
public SimpleJdbcInsert(JdbcTemplate jdbcTemplate)
Alternative Constructor that takes one parameter with the JdbcTemplate to be used.- 参数:
jdbcTemplate
- theJdbcTemplate
to use- 另请参阅:
JdbcAccessor.setDataSource(javax.sql.DataSource)
方法详细资料
withTableName
public SimpleJdbcInsert withTableName(String tableName)
从接口复制的说明:SimpleJdbcInsertOperations
Specify the table name to be used for the insert.- 指定者:
withTableName
在接口中SimpleJdbcInsertOperations
- 参数:
tableName
- the name of the stored table- 返回:
- the instance of this SimpleJdbcInsert
withSchemaName
public SimpleJdbcInsert withSchemaName(String schemaName)
从接口复制的说明:SimpleJdbcInsertOperations
Specify the schema name, if any, to be used for the insert.- 指定者:
withSchemaName
在接口中SimpleJdbcInsertOperations
- 参数:
schemaName
- the name of the schema- 返回:
- the instance of this SimpleJdbcInsert
withCatalogName
public SimpleJdbcInsert withCatalogName(String catalogName)
从接口复制的说明:SimpleJdbcInsertOperations
Specify the catalog name, if any, to be used for the insert.- 指定者:
withCatalogName
在接口中SimpleJdbcInsertOperations
- 参数:
catalogName
- the name of the catalog- 返回:
- the instance of this SimpleJdbcInsert
usingColumns
public SimpleJdbcInsert usingColumns(String... columnNames)
从接口复制的说明:SimpleJdbcInsertOperations
Specify the column names that the insert statement should be limited to use.- 指定者:
usingColumns
在接口中SimpleJdbcInsertOperations
- 参数:
columnNames
- one or more column names- 返回:
- the instance of this SimpleJdbcInsert
usingGeneratedKeyColumns
public SimpleJdbcInsert usingGeneratedKeyColumns(String... columnNames)
从接口复制的说明:SimpleJdbcInsertOperations
Specify the names of any columns that have auto generated keys.- 指定者:
usingGeneratedKeyColumns
在接口中SimpleJdbcInsertOperations
- 参数:
columnNames
- one or more column names- 返回:
- the instance of this SimpleJdbcInsert
withoutTableColumnMetaDataAccess
public SimpleJdbcInsertOperations withoutTableColumnMetaDataAccess()
从接口复制的说明:SimpleJdbcInsertOperations
Turn off any processing of column meta-data information obtained via JDBC.- 指定者:
withoutTableColumnMetaDataAccess
在接口中SimpleJdbcInsertOperations
- 返回:
- the instance of this SimpleJdbcInsert
includeSynonymsForTableColumnMetaData
public SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData()
从接口复制的说明:SimpleJdbcInsertOperations
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.
- 指定者:
includeSynonymsForTableColumnMetaData
在接口中SimpleJdbcInsertOperations
- 返回:
- the instance of this SimpleJdbcInsert
useNativeJdbcExtractorForMetaData
public SimpleJdbcInsertOperations useNativeJdbcExtractorForMetaData(NativeJdbcExtractor nativeJdbcExtractor)
从接口复制的说明:SimpleJdbcInsertOperations
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.
- 指定者:
useNativeJdbcExtractorForMetaData
在接口中SimpleJdbcInsertOperations
- 返回:
- the instance of this SimpleJdbcInsert
execute
public int execute(Map<String,?> args)
从接口复制的说明:SimpleJdbcInsertOperations
Execute the insert using the values passed in.- 指定者:
execute
在接口中SimpleJdbcInsertOperations
- 参数:
args
- Map containing column names and corresponding value- 返回:
- the number of rows affected as returned by the JDBC driver
execute
public int execute(SqlParameterSource parameterSource)
从接口复制的说明:SimpleJdbcInsertOperations
Execute the insert using the values passed in.- 指定者:
execute
在接口中SimpleJdbcInsertOperations
- 参数:
parameterSource
- SqlParameterSource containing values to use for insert- 返回:
- the number of rows affected as returned by the JDBC driver
executeAndReturnKey
public Number executeAndReturnKey(Map<String,?> args)
从接口复制的说明:SimpleJdbcInsertOperations
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
在接口中SimpleJdbcInsertOperations
- 参数:
args
- Map containing column names and corresponding value- 返回:
- the generated key value
executeAndReturnKey
public Number executeAndReturnKey(SqlParameterSource parameterSource)
从接口复制的说明:SimpleJdbcInsertOperations
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
在接口中SimpleJdbcInsertOperations
- 参数:
parameterSource
- SqlParameterSource containing values to use for insert- 返回:
- the generated key value.
executeAndReturnKeyHolder
public KeyHolder executeAndReturnKeyHolder(Map<String,?> args)
从接口复制的说明:SimpleJdbcInsertOperations
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
在接口中SimpleJdbcInsertOperations
- 参数:
args
- Map containing column names and corresponding value- 返回:
- the KeyHolder containing all generated keys
executeAndReturnKeyHolder
public KeyHolder executeAndReturnKeyHolder(SqlParameterSource parameterSource)
从接口复制的说明:SimpleJdbcInsertOperations
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
在接口中SimpleJdbcInsertOperations
- 参数:
parameterSource
- SqlParameterSource containing values to use for insert- 返回:
- the KeyHolder containing all generated keys
executeBatch
public int[] executeBatch(Map<String,?>... batch)
从接口复制的说明:SimpleJdbcInsertOperations
Execute a batch insert using the batch of values passed in.- 指定者:
executeBatch
在接口中SimpleJdbcInsertOperations
- 参数:
batch
- an array of Maps containing a batch of column names and corresponding value- 返回:
- the array of number of rows affected as returned by the JDBC driver
executeBatch
public int[] executeBatch(SqlParameterSource... batch)
从接口复制的说明:SimpleJdbcInsertOperations
Execute a batch insert using the batch of values passed in.- 指定者:
executeBatch
在接口中SimpleJdbcInsertOperations
- 参数:
batch
- an array of SqlParameterSource containing values for the batch- 返回:
- the array of number of rows affected as returned by the JDBC driver