Data Types
Overview
Most of the data types are self explanatory and are adapted to the database in use. Refer to the database documentation for its data types specifics.
Every type below lives in
org.dbunit.dataset.datatype.
Which SQL type maps to which of these is normally decided automatically —
see the DataType Factory property for how
to override or extend the mapping, and
Database-Specific Guides for vendor-specific types
(Oracle SDO_GEOMETRY, PostgreSQL citext/interval/inet, MSSQL
uniqueidentifier/datetimeoffset, MariaDB UUID/INET4/INET6, and
more) not covered here.
How a dataset field’s text becomes a typed value of one of these types —
nulls, empty strings, the [TEXT|BASE64|FILE|URL] and [now…] bracket
syntaxes, UUID literals, booleans and numbers from strings — is covered in
Dataset Values.
| Type | Java Type | Notes |
|---|---|---|
BigIntegerDataType |
java.math.BigInteger |
The default mapping for SQL BIGINT. |
BinaryStreamDataType |
byte[] |
Reads via ResultSet.getBinaryStream() instead of getBytes(). Not registered by default — used by vendor factories for large binary values, e.g. Oracle’s LONG RAW and streamed BLOB (OracleDataTypeFactory/Oracle10DataTypeFactory). |
BitDataType |
Boolean |
The default mapping for SQL BIT; extends BooleanDataType. |
BlobDataType |
byte[] |
The default mapping for SQL BLOB. See Dataset Values for the [TEXT|BASE64|FILE|URL] load syntax. |
BooleanDataType |
Boolean |
The default mapping for SQL BOOLEAN. |
BytesDataType |
byte[] |
Abstract base for the binary types above/below; not itself registered for any SQL type. |
ClobDataType |
String |
The default mapping for SQL CLOB; extends StringDataType. |
DateDataType |
java.sql.Date |
The default mapping for SQL DATE. See Dataset Values for literal and relative ([now…]) date syntax. |
DoubleDataType |
Double |
The default mapping for SQL DOUBLE and SQL FLOAT — see the naming note under FloatDataType. |
FloatDataType |
Float |
The default mapping for SQL REAL. Confusingly, SQL FLOAT maps to DoubleDataType/Java Double while SQL REAL maps here, to Java Float — this mirrors java.sql.Types, not a dbUnit choice. |
IntegerDataType |
Integer |
The default mapping for SQL TINYINT, SMALLINT, and INTEGER. |
LongDataType |
Long |
An alternate BIGINT mapping using Java Long instead of BigInteger. Not registered by default (DataType.BIGINT uses BigIntegerDataType); wire it in yourself via a custom IDataTypeFactory if you prefer Long. |
NumberDataType |
java.math.BigDecimal |
The default mapping for SQL NUMERIC/DECIMAL. |
NumberTolerantDataType |
java.math.BigDecimal |
A NumberDataType variant comparing within a tolerance instead of requiring an exact match. See NumberTolerantDataType below. |
StringDataType |
String |
The default mapping for SQL CHAR, VARCHAR, LONGVARCHAR, NCHAR, NVARCHAR, and LONGNVARCHAR. |
StringIgnoreCaseDataType |
String |
A StringDataType variant comparing case-insensitively. See StringIgnoreCaseDataType below. |
TimeDataType |
java.sql.Time |
The default mapping for SQL TIME. See Dataset Values for literal and relative ([now…]) time syntax. |
TimestampDataType |
java.sql.Timestamp |
The default mapping for SQL TIMESTAMP. See Dataset Values for literal and relative ([now…]) timestamp syntax. |
UuidAwareBytesDataType |
byte[] |
The default mapping for SQL BINARY/VARBINARY/LONGVARBINARY — a BytesDataType variant additionally recognizing a UUID literal. See UuidAwareBytesDataType below and Dataset Values for the syntax. |
NumberTolerantDataType
NumberTolerantDataType JavaDoc
A NumberDataType that accepts a value within a tolerated delta instead of
requiring an exact match — comparable to JUnit’s
assertEquals(double, double, double delta). The delta can be an absolute
amount or a percentage of the expected value.
Register a tolerance per table/column by adding a
ToleratedDeltaMap.ToleratedDelta
to a DefaultDataTypeFactory (or a vendor factory extending it):
DefaultDataTypeFactory factory = new DefaultDataTypeFactory();
// allow ACCOUNT.BALANCE actual/expected values to differ by up to 0.01
factory.addToleratedDelta(new ToleratedDeltaMap.ToleratedDelta("ACCOUNT", "BALANCE", 0.01));
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, factory);Pass true as a fourth constructor argument to treat the delta as a
percentage of the expected value instead of an absolute amount. For
comparisons that don’t need per-column DataType registration, see the
ValueComparer-based tolerance implementations instead — ValueComparer Comparison.
StringIgnoreCaseDataType
StringIgnoreCaseDataType JavaDoc
A StringDataType that compares values with String.compareToIgnoreCase()
instead of exact equality. Like NumberTolerantDataType, register it for
specific columns through a custom IDataTypeFactory (or by returning it
directly from createDataType() for the columns that need case-insensitive
comparison) set via DatabaseConfig.PROPERTY_DATATYPE_FACTORY — see
the DataType Factory property.
UuidAwareBytesDataType
UuidAwareBytesDataType JavaDoc
The default DataType for SQL BINARY/VARBINARY/LONGVARBINARY columns. It
behaves like BytesDataType, plus recognizes a UUID literal so UUIDs stored
in binary columns need not be base64- or hex-encoded by hand. The
uuid'…' field syntax is documented in
Dataset Values.


