@ComponentProfile(summary="Insert a CSV file into a database", tag="service,csv,jdbc", since="3.6.5") public class BatchInsertCSV extends JdbcMapInsert
This creates insert statements based on the CSV file. The actual insert statement will only be generated once based on the first CSV line and executed the appropriate number of times.
firstname, lastname, dob
alice, bob, 2017-01-01
bob, smith, 2017-01-01
carol, smith,2017-01-01
will effectively execute the following statement INSERT INTO table (firstname,lastname,dob) VALUES (?,?,?)
3
times; batching as required using PreparedStatement.addBatch()
/ Statement.executeBatch()
.
Note that no parsing/assertion of the column names will be done, so if they are invalid SQL columns then it's going to be fail.
In the adapter configuration file this class is aliased as csv-jdbc-batch-insert which is the preferred alternative to the fully qualified classname when building your configuration.
JdbcMapInsert.BasicType, JdbcMapInsert.InsertWrapper, JdbcMapInsert.StatementParam, JdbcMapInsert.StatementWrapper
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BATCH_WINDOW |
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
BatchInsertCSV() |
Modifier and Type | Method and Description |
---|---|
protected static int |
accumulate(int[] rc) |
void |
doService(AdaptrisMessage msg) |
java.lang.Integer |
getBatchWindow() |
PreferenceBuilder |
getPreferenceBuilder() |
void |
setBatchWindow(java.lang.Integer i)
Set the batch window for operations.
|
void |
setPreferenceBuilder(PreferenceBuilder formatBuilder) |
addUpdatedMetadata, buildStatementParam, closeJdbcService, columnBookend, getColumnBookendCharacter, getFieldMappings, getRowsAffectedMetadataKey, getTable, handleInsert, initJdbcService, prepareService, setColumnBookendCharacter, setFieldMappings, setRowsAffectedMetadataKey, setTable, startService, stopService, table, withColumnBookend, withMappings, withRowsAffectedMetadataKey, withTable
applyTimeout, closeService, commit, createStatement, getConnection, getConnection, getStatementTimeout, initService, prepare, prepareStatement, prepareStatement, rollback, setConnection, setStatementTimeout, start, stop
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setLookupName, setUniqueId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
continueOnFailure, isBranching, setUniqueId
createName, createQualifier, isTrackingEndpoint
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
getUniqueId
close, init
getLookupName
public static final int DEFAULT_BATCH_WINDOW
public PreferenceBuilder getPreferenceBuilder()
public void setPreferenceBuilder(PreferenceBuilder formatBuilder)
formatBuilder
- the formatBuilder to setpublic void doService(AdaptrisMessage msg) throws ServiceException
ServiceException
protected static int accumulate(int[] rc) throws java.sql.SQLException
java.sql.SQLException
public java.lang.Integer getBatchWindow()
public void setBatchWindow(java.lang.Integer i)
i
- the batchWindow to set; default is 1024 if not specified.