Skip to main content

MariaDB/MySQL Type Support

Foundations JDBC provides comprehensive support for MariaDB and MySQL data types, including unsigned integers, spatial types, and MySQL-specific features.

Integer Types (Signed)

MariaDB TypeJava TypeRange
TINYINTByte-128 to 127
SMALLINTShort-32,768 to 32,767
MEDIUMINTInteger-8,388,608 to 8,388,607
INTInteger-2,147,483,648 to 2,147,483,647
BIGINTLong-2^63 to 2^63-1
MariaType<Byte> tinyType = MariaTypes.tinyint;
MariaType<Integer> intType = MariaTypes.int_;
MariaType<Long> bigType = MariaTypes.bigint;

Integer Types (Unsigned)

MariaDB supports unsigned integers, which are mapped to the next larger Java type:

MariaDB TypeJava TypeRange
TINYINT UNSIGNEDShort0 to 255
SMALLINT UNSIGNEDInteger0 to 65,535
MEDIUMINT UNSIGNEDInteger0 to 16,777,215
INT UNSIGNEDLong0 to 4,294,967,295
BIGINT UNSIGNEDBigInteger0 to 2^64-1
MariaType<Short> unsignedTiny = MariaTypes.tinyintUnsigned;
MariaType<Long> unsignedInt = MariaTypes.intUnsigned;
MariaType<BigInteger> unsignedBig = MariaTypes.bigintUnsigned;

Fixed-Point Types

MariaDB TypeJava TypeNotes
DECIMAL(p,s)BigDecimalExact numeric
NUMERIC(p,s)BigDecimalAlias for DECIMAL
MariaType<BigDecimal> decimalType = MariaTypes.decimal;
MariaType<BigDecimal> preciseDecimal = MariaTypes.decimal(10, 2); // DECIMAL(10,2)

Floating-Point Types

MariaDB TypeJava TypeNotes
FLOATFloat32-bit IEEE 754
DOUBLEDouble64-bit IEEE 754
MariaType<Float> floatType = MariaTypes.float_;
MariaType<Double> doubleType = MariaTypes.double_;

Boolean Type

MariaDB TypeJava TypeNotes
BOOLEAN / BOOLBooleanAlias for TINYINT(1)
BIT(1)BooleanSingle bit as boolean
MariaType<Boolean> boolType = MariaTypes.bool;
MariaType<Boolean> bitBool = MariaTypes.bit1;

Bit Types

MariaDB TypeJava TypeNotes
BIT(n)byte[]Bit field (n > 1)
MariaType<byte[]> bitType = MariaTypes.bit;

String Types

MariaDB TypeJava TypeMax Length
CHAR(n)String255 chars
VARCHAR(n)String65,535 bytes
TINYTEXTString255 bytes
TEXTString65,535 bytes
MEDIUMTEXTString16 MB
LONGTEXTString4 GB
MariaType<String> charType = MariaTypes.char_(10);   // CHAR(10)
MariaType<String> varcharType = MariaTypes.varchar(255); // VARCHAR(255)
MariaType<String> textType = MariaTypes.text;
MariaType<String> longType = MariaTypes.longtext;

Binary Types

MariaDB TypeJava TypeMax Length
BINARY(n)byte[]Fixed n bytes
VARBINARY(n)byte[]Up to n bytes
TINYBLOBbyte[]255 bytes
BLOBbyte[]65,535 bytes
MEDIUMBLOBbyte[]16 MB
LONGBLOBbyte[]4 GB
MariaType<byte[]> binaryType = MariaTypes.binary(16);
MariaType<byte[]> varbinaryType = MariaTypes.varbinary(255);
MariaType<byte[]> blobType = MariaTypes.blob;

Date/Time Types

MariaDB TypeJava TypeNotes
DATELocalDateDate only
TIMELocalTimeTime only
DATETIMELocalDateTimeDate and time
TIMESTAMPLocalDateTimeWith auto-update
YEARYear4-digit year
MariaType<LocalDate> dateType = MariaTypes.date;
MariaType<LocalTime> timeType = MariaTypes.time;
MariaType<LocalDateTime> datetimeType = MariaTypes.datetime;
MariaType<Year> yearType = MariaTypes.year;

// With fractional seconds precision
MariaType<LocalTime> timeFsp = MariaTypes.time(6); // TIME(6)
MariaType<LocalDateTime> dtFsp = MariaTypes.datetime(3); // DATETIME(3)

ENUM Type

MariaDB TypeJava Type
ENUM('a','b','c')Java Enum
// Define your Java enum
public enum Status { PENDING, ACTIVE, COMPLETED }

// Create MariaType for it
MariaType<Status> statusType = MariaTypes.ofEnum("status", Status::valueOf);

SET Type

MariaDB TypeJava Type
SET('a','b','c')MariaSet
MariaType<MariaSet> setType = MariaTypes.set;

// Create and use sets
MariaSet values = MariaSet.of("read", "write");
String csv = values.toCommaSeparated(); // "read,write"

JSON Type

MariaDB TypeJava Type
JSONJson
MariaType<Json> jsonType = MariaTypes.json;

Json data = new Json("{\"name\": \"John\", \"age\": 30}");

Network Types (MariaDB 10.10+)

MariaDB TypeJava TypeDescription
INET4Inet4IPv4 address
INET6Inet6IPv6 address
MariaType<Inet4> inet4Type = MariaTypes.inet4;
MariaType<Inet6> inet6Type = MariaTypes.inet6;

Inet4 ipv4 = Inet4.parse("192.168.1.1");
Inet6 ipv6 = Inet6.parse("::1");

Spatial Types

MariaDB spatial types use the MariaDB Connector/J geometry classes:

MariaDB TypeJava TypeDescription
GEOMETRYGeometryAny geometry
POINTPointSingle point
LINESTRINGLineStringLine of points
POLYGONPolygonClosed polygon
MULTIPOINTMultiPointMultiple points
MULTILINESTRINGMultiLineStringMultiple lines
MULTIPOLYGONMultiPolygonMultiple polygons
GEOMETRYCOLLECTIONGeometryCollectionMixed geometries
MariaType<Point> pointType = MariaTypes.point;
MariaType<Polygon> polygonType = MariaTypes.polygon;
MariaType<GeometryCollection> gcType = MariaTypes.geometrycollection;

// Create a point
Point p = new Point(1.0, 2.0);

Nullable Types

Any type can be made nullable using .nullable():

MariaType<Integer> notNull = MariaTypes.int_;
MariaType<Integer> nullable = MariaTypes.int_.nullable();

Custom Domain Types

Wrap base types with custom Java types using bimap:

// Wrapper type
public record UserId(Long value) {}

// Create MariaType from bigint
MariaType<UserId> userIdType = MariaTypes.bigint.bimap(UserId::new, UserId::value);