APIdia Launch Partner
Top Description Inners Fields Constructors Methods
io.github.spannm.jackcess.util

public final Class ImportUtil

extends Object
Class Inheritance
Imports
io.github.spannm.jackcess.ColumnBuilder, .DataType, .Database, .Table, .TableBuilder, java.io.BufferedReader, .EOFException, .File, .FileInputStream, .IOException, .InputStreamReader, java.nio.charset.Charset, java.sql.ResultSet, .ResultSetMetaData, .SQLException, java.util.ArrayList, .List, java.util.regex.Matcher, .Pattern

Utility class for importing tables to an Access database from other sources. See the Builder for convenient configuration of the import functionality. Note that most scenarios for customizing input data can be handled by implementing a custom ImportFilter.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImportUtil.Builder

Builder which simplifies configuration of an import operation.

Field Summary

Modifier and TypeField and Description
private static final int
COPY_TABLE_BATCH_SIZE

Batch commit size for copying other result sets into this database

pack-priv static final String
LINE_SEPARATOR

the platform line separator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Table
createUniqueTable(Database db, String name, List<ColumnBuilder> columns, ResultSetMetaData md, ImportFilter filter)

Returns a new table with a unique name and the given table definition.

public static String

Returns:

the name of the imported table
importFile
(File
Source file to import
f
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
)

Copy a delimited text file into a new table in this database.

public static String

Returns:

the name of the imported table
importFile
(File
Source file to import
f
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
,
ImportFilter
valid import filter
filter
)

Copy a delimited text file into a new table in this database.

public static String

Returns:

the name of the imported table
importFile
(File
Source file to import
f
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
,
char
the quote character
quote
,
ImportFilter
valid import filter
filter
,
boolean
if true use current table if it already exists, otherwise, create new table with unique name
useExistingTable
)

Copy a delimited text file into a new table in this database.

public static String

Returns:

the name of the imported table
importFile
(File
Source file to import
f
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
,
char
the quote character
quote
,
ImportFilter
valid import filter
filter
,
boolean
if true use current table if it already exists, otherwise, create new table with unique name
useExistingTable
,
boolean
if false the first line is not a header row, only valid if useExistingTable is true
header
)

Copy a delimited text file into a new table in this database.

public static String

Returns:

the name of the imported table
importReader
(BufferedReader
Source reader to import
in
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
)

Copy a delimited text file into a new table in this database.

public static String

Returns:

the name of the imported table
importReader
(BufferedReader
Source reader to import
in
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
,
ImportFilter
valid import filter
filter
)

Copy a delimited text file into a new table in this database.

public static String

Returns:

the name of the imported table
importReader
(BufferedReader
Source reader to import
in
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
,
ImportFilter
valid import filter
filter
,
boolean
if true use current table if it already exists, otherwise, create new table with unique name
useExistingTable
)

Copy a delimited text file into a new (or optionally exixsting) table in this database.

public static String

Returns:

the name of the imported table
importReader
(BufferedReader
Source reader to import
in
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
,
char
the quote character
quote
,
ImportFilter
valid import filter
filter
,
boolean
if true use current table if it already exists, otherwise, create new table with unique name
useExistingTable
)

Copy a delimited text file into a new (or optionally exixsting) table in this database.

public static String

Returns:

the name of the imported table
importReader
(BufferedReader
Source reader to import
in
,
Database db, String
Name of the new table to create
name
,
String
Regular expression representing the delimiter string.
delim
,
char
the quote character
quote
,
ImportFilter
valid import filter
filter
,
boolean
if true use current table if it already exists, otherwise, create new table with unique name
useExistingTable
,
boolean
if false the first line is not a header row, only valid if useExistingTable is true
header
)

Copy a delimited text file into a new (or optionally exixsting) table in this database.

public static String

Returns:

the name of the copied table
importResultSet
(ResultSet
ResultSet to copy from
source
,
Database db, String
Name of the new table to create
name
)

Copy an existing JDBC ResultSet into a new table in this database.

public static String

Returns:

the name of the imported table
importResultSet
(ResultSet
ResultSet to copy from
source
,
Database db, String
Name of the new table to create
name
,
ImportFilter
valid import filter
filter
)

Copy an existing JDBC ResultSet into a new table in this database.

public static String

Returns:

the name of the imported table
importResultSet
(ResultSet
ResultSet to copy from
source
,
Database db, String
Name of the new table to create
name
,
ImportFilter
valid import filter
filter
,
boolean
if true use current table if it already exists, otherwise, create new table with unique name
useExistingTable
)

Copy an existing JDBC ResultSet into a new (or optionally existing) table in this database.

private static Object[]
splitLine(String line, Pattern delim, char quote, BufferedReader in, int numColumns)

Splits the given line using the given delimiter pattern and quote character.

public static List<ColumnBuilder>

Returns:

a List of Columns
toColumns
(ResultSetMetaData md)

Returns a List of Column instances converted from the given ResultSetMetaData (this is the same method used by the various importResultSet() methods).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COPY_TABLE_BATCH_SIZEback to summary
private static final int COPY_TABLE_BATCH_SIZE

Batch commit size for copying other result sets into this database

LINE_SEPARATORback to summary
pack-priv static final String LINE_SEPARATOR

the platform line separator

Constructor Detail

ImportUtilback to summary
private ImportUtil()

Method Detail

createUniqueTableback to summary
private static Table createUniqueTable(Database db, String name, List<ColumnBuilder> columns, ResultSetMetaData md, ImportFilter filter) throws IOException

Returns a new table with a unique name and the given table definition.

importFileback to summary
public static String importFile(File f, Database db, String name, String delim) throws IOException

Copy a delimited text file into a new table in this database.

Equivalent to: importFile(f, name, db, delim, SimpleImportFilter.INSTANCE);

Parameters
f:File

Source file to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

Returns:String

the name of the imported table

See Also
importFile(File, Database, String, String, ImportFilter), Builder
importFileback to summary
public static String importFile(File f, Database db, String name, String delim, ImportFilter filter) throws IOException

Copy a delimited text file into a new table in this database.

Equivalent to: importFile(f, name, db, delim, "'", filter, false);

Parameters
f:File

Source file to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

filter:ImportFilter

valid import filter

Returns:String

the name of the imported table

See Also
importReader(BufferedReader, Database, String, String, ImportFilter), Builder
importFileback to summary
public static String importFile(File f, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable) throws IOException

Copy a delimited text file into a new table in this database.

Equivalent to: importReader(new BufferedReader(new FileReader(f)), db, name, delim, "'", filter, useExistingTable, true);

Parameters
f:File

Source file to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

quote:char

the quote character

filter:ImportFilter

valid import filter

useExistingTable:boolean

if true use current table if it already exists, otherwise, create new table with unique name

Returns:String

the name of the imported table

See Also
importReader(BufferedReader, Database, String, String, ImportFilter, boolean), Builder
importFileback to summary
public static String importFile(File f, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable, boolean header) throws IOException

Copy a delimited text file into a new table in this database.

Equivalent to: importReader(new BufferedReader(new FileReader(f)), db, name, delim, "'", filter, useExistingTable, header);

Parameters
f:File

Source file to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

quote:char

the quote character

filter:ImportFilter

valid import filter

useExistingTable:boolean

if true use current table if it already exists, otherwise, create new table with unique name

header:boolean

if false the first line is not a header row, only valid if useExistingTable is true

Returns:String

the name of the imported table

See Also
importReader(BufferedReader, Database, String, String, char, ImportFilter, boolean, boolean), Builder
importReaderback to summary
public static String importReader(BufferedReader in, Database db, String name, String delim) throws IOException

Copy a delimited text file into a new table in this database.

Equivalent to: importReader(in, db, name, delim, SimpleImportFilter.INSTANCE);

Parameters
in:BufferedReader

Source reader to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

Returns:String

the name of the imported table

See Also
importReader(BufferedReader, Database, String, String, ImportFilter), Builder
importReaderback to summary
public static String importReader(BufferedReader in, Database db, String name, String delim, ImportFilter filter) throws IOException

Copy a delimited text file into a new table in this database.

Equivalent to: importReader(in, db, name, delim, filter, false);

Parameters
in:BufferedReader

Source reader to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

filter:ImportFilter

valid import filter

Returns:String

the name of the imported table

See Also
importReader(BufferedReader, Database, String, String, ImportFilter, boolean), Builder
importReaderback to summary
public static String importReader(BufferedReader in, Database db, String name, String delim, ImportFilter filter, boolean useExistingTable) throws IOException

Copy a delimited text file into a new (or optionally exixsting) table in this database.

Equivalent to: importReader(in, db, name, delim, '"', filter, false);

Parameters
in:BufferedReader

Source reader to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

filter:ImportFilter

valid import filter

useExistingTable:boolean

if true use current table if it already exists, otherwise, create new table with unique name

Returns:String

the name of the imported table

See Also
Builder
importReaderback to summary
public static String importReader(BufferedReader in, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable) throws IOException

Copy a delimited text file into a new (or optionally exixsting) table in this database.

Equivalent to: importReader(in, db, name, delim, '"', filter, useExistingTable, true);

Parameters
in:BufferedReader

Source reader to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

quote:char

the quote character

filter:ImportFilter

valid import filter

useExistingTable:boolean

if true use current table if it already exists, otherwise, create new table with unique name

Returns:String

the name of the imported table

See Also
Builder
importReaderback to summary
public static String importReader(BufferedReader in, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable, boolean header) throws IOException

Copy a delimited text file into a new (or optionally exixsting) table in this database.

Parameters
in:BufferedReader

Source reader to import

name:String

Name of the new table to create

delim:String

Regular expression representing the delimiter string.

quote:char

the quote character

filter:ImportFilter

valid import filter

useExistingTable:boolean

if true use current table if it already exists, otherwise, create new table with unique name

header:boolean

if false the first line is not a header row, only valid if useExistingTable is true

Returns:String

the name of the imported table

importResultSetback to summary
public static String importResultSet(ResultSet source, Database db, String name) throws SQLException, IOException

Copy an existing JDBC ResultSet into a new table in this database.

Equivalent to: importResultSet(source, db, name, SimpleImportFilter.INSTANCE);

Parameters
source:ResultSet

ResultSet to copy from

name:String

Name of the new table to create

Returns:String

the name of the copied table

See Also
importResultSet(ResultSet, Database, String, ImportFilter), Builder
importResultSetback to summary
public static String importResultSet(ResultSet source, Database db, String name, ImportFilter filter) throws SQLException, IOException

Copy an existing JDBC ResultSet into a new table in this database.

Equivalent to: importResultSet(source, db, name, filter, false);

Parameters
source:ResultSet

ResultSet to copy from

name:String

Name of the new table to create

filter:ImportFilter

valid import filter

Returns:String

the name of the imported table

See Also
importResultSet(ResultSet, Database, String, ImportFilter, boolean), Builder
importResultSetback to summary
public static String importResultSet(ResultSet source, Database db, String name, ImportFilter filter, boolean useExistingTable) throws SQLException, IOException

Copy an existing JDBC ResultSet into a new (or optionally existing) table in this database.

Parameters
source:ResultSet

ResultSet to copy from

name:String

Name of the new table to create

filter:ImportFilter

valid import filter

useExistingTable:boolean

if true use current table if it already exists, otherwise, create new table with unique name

Returns:String

the name of the imported table

See Also
Builder
splitLineback to summary
private static Object[] splitLine(String line, Pattern delim, char quote, BufferedReader in, int numColumns) throws IOException

Splits the given line using the given delimiter pattern and quote character. May read additional lines for quotes spanning newlines.

toColumnsback to summary
public static List<ColumnBuilder> toColumns(ResultSetMetaData md) throws SQLException, IOException

Returns a List of Column instances converted from the given ResultSetMetaData (this is the same method used by the various importResultSet() methods).

Returns:List<ColumnBuilder>

a List of Columns

io.github.spannm.jackcess.util back to summary

public Class ImportUtil.Builder

extends Object
Class Inheritance

Builder which simplifies configuration of an import operation.

Field Summary

Modifier and TypeField and Description
private Database
private String
private ImportFilter
private boolean
private char
private String
private boolean

Constructor Summary

AccessConstructor and Description
public
public
Builder(Database db, String tableName)

Method Summary

Modifier and TypeMethod and Description
public String
importFile(File f)

Imports the given delimited file into a table, using the settings of this builder.

public String
importReader(BufferedReader reader)

Imports delimited data from the given reader into a table, using the settings of this builder.

public String
importResultSet(ResultSet source)

Imports the given result set into a table, using the settings of this builder.

public ImportUtil.Builder
public ImportUtil.Builder
public ImportUtil.Builder
public ImportUtil.Builder
withHeader(boolean newHeader)

public ImportUtil.Builder
withQuote(char newQuote)

public ImportUtil.Builder
withTableName(String newTableName)

public ImportUtil.Builder
withUseExistingTable(boolean newUseExistingTable)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dbback to summary
private Database db
delimback to summary
private String delim
filterback to summary
private ImportFilter filter
headerback to summary
private boolean header
quoteback to summary
private char quote
tableNameback to summary
private String tableName
useExistingTableback to summary
private boolean useExistingTable

Constructor Detail

Builderback to summary
public Builder(Database db)
Builderback to summary
public Builder(Database db, String tableName)

Method Detail

importFileback to summary
public String importFile(File f) throws IOException

Imports the given delimited file into a table, using the settings of this builder.

See Also
ImportUtil#importFile(File, Database, String, String, char, ImportFilter, boolean, boolean)
importReaderback to summary
public String importReader(BufferedReader reader) throws IOException

Imports delimited data from the given reader into a table, using the settings of this builder.

See Also
ImportUtil#importReader(BufferedReader, Database, String, String, char, ImportFilter, boolean, boolean)
importResultSetback to summary
public String importResultSet(ResultSet source) throws SQLException, IOException

Imports the given result set into a table, using the settings of this builder.

See Also
ImportUtil#importResultSet(ResultSet, Database, String, ImportFilter, boolean)
withDatabaseback to summary
public ImportUtil.Builder withDatabase(Database newDb)
withDelimiterback to summary
public ImportUtil.Builder withDelimiter(String newDelim)
withFilterback to summary
public ImportUtil.Builder withFilter(ImportFilter newFilter)
withHeaderback to summary
public ImportUtil.Builder withHeader(boolean newHeader)
withQuoteback to summary
public ImportUtil.Builder withQuote(char newQuote)
withTableNameback to summary
public ImportUtil.Builder withTableName(String newTableName)
withUseExistingTableback to summary
public ImportUtil.Builder withUseExistingTable(boolean newUseExistingTable)