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
val tinyType: MariaType<Byte> = MariaTypes.tinyint
val intType: MariaType<Int> = MariaTypes.int_
val bigType: MariaType<Long> = MariaTypes.bigint

Integer Types (Unsigned)

MariaDB supports unsigned integers, which are wrapped in type-safe unsigned types:

MariaDB TypeJava TypeRange
TINYINT UNSIGNEDUint10 to 255
SMALLINT UNSIGNEDUint20 to 65,535
MEDIUMINT UNSIGNEDUint40 to 16,777,215
INT UNSIGNEDUint40 to 4,294,967,295
BIGINT UNSIGNEDUint80 to 2^64-1
val unsignedTiny: MariaType<Uint1> = MariaTypes.tinyintUnsigned
val unsignedInt: MariaType<Uint4> = MariaTypes.intUnsigned
val unsignedBig: MariaType<Uint8> = MariaTypes.bigintUnsigned

Fixed-Point Types

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

Floating-Point Types

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

Boolean Type

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

Bit Types

MariaDB TypeJava TypeNotes
BIT(n)byte[]Bit field (n > 1)
val bitType: MariaType<ByteArray> = 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
val charType: MariaType<String> = MariaTypes.char_Of(10)
val varcharType: MariaType<String> = MariaTypes.varcharOf(255)
val textType: MariaType<String> = MariaTypes.text
val longType: MariaType<String> = 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
val binaryType: MariaType<ByteArray> = MariaTypes.binaryOf(16)
val varbinaryType: MariaType<ByteArray> = MariaTypes.varbinaryOf(255)
val blobType: MariaType<ByteArray> = MariaTypes.blob

Date/Time Types

MariaDB TypeJava TypeNotes
DATELocalDateNaive date, no zone
TIMELocalTimeNaive time, no zone
DATETIMELocalDateTimeNaive timestamp, no zone
TIMESTAMPLocalDateTimeSession-TZ converted — see note below
YEARYear4-digit year
val dateType: MariaType<LocalDate> = MariaTypes.date
val timeType: MariaType<LocalTime> = MariaTypes.time
val datetimeType: MariaType<LocalDateTime> = MariaTypes.datetime
val yearType: MariaType<Year> = MariaTypes.year

// With fractional seconds precision
val timeFsp: MariaType<LocalTime> = MariaTypes.timeOf(6)
val dtFsp: MariaType<LocalDateTime> = MariaTypes.datetimeOf(3)
MariaDB has no zone-preserving timestamp type

None of MariaDB's temporal types store time-zone information in the column itself:

  • DATE, TIME, DATETIME are naive — the value you write is the value you read back verbatim, whatever zone the writer was in.
  • TIMESTAMP is stored as UTC seconds internally but is converted to and from the session's time_zone variable on every read/write. Two clients with different session timezones see different wall-clock values for the same row — round-trip stability depends on time_zone being set consistently.

All four map to LocalDateTime (or LocalDate/LocalTime) because LocalDateTime is the Java type that matches the naive-wall-clock semantic. Instant, OffsetDateTime, and ZonedDateTime would all misrepresent what the column holds.

For application-level "point in time" values, the idiomatic approach on MariaDB is either: (a) DATETIME with all writes normalized to UTC in application code, or (b) BIGINT epoch milliseconds. Neither matches a single built-in MariaDB type cleanly.

ENUM Type

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

// Create MariaType — reified, derives ENUM literal automatically
val statusType: MariaType<Status> = MariaTypes.ofEnum<Status>()
The values()-based factory derives everything

MariaDB/MySQL enums aren't named types — they're declared inline on the column. The values()-based factory derives the full ENUM('A','B','C') literal automatically:

MariaTypes.ofEnum(State.values())          // Java
MariaTypes.ofEnum<State>()                 // Kotlin (reified)
MariaTypes.ofEnum(State.values)            // Scala 3

The column DDL must match the derived literal — ENUM('PENDING','ACTIVE','COMPLETED') in declaration order, using each constant's name.

Fall back to the string-based overload ofEnum("ENUM('pending',…)", s -> State.valueOf(s.toUpperCase())) when the database labels differ from the Java enum's name() values (e.g. lowercase labels in the DB).

SET Type

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

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

JSON Type

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

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

Network Types (MariaDB 10.10+)

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

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

UUID Type (MariaDB 10.7+)

MariaDB TypeJava TypeDescription
UUIDjava.util.UUID128-bit UUID
val uuidType: MariaType<UUID> = MariaTypes.uuid

VECTOR Type (MariaDB 11.7+)

MariaDB TypeJava TypeDescription
VECTOR(n)VectorFixed-dimension float vector for embeddings
val embedding: MariaType<Vector> = MariaTypes.vector(1536)

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
val pointType: MariaType<Point> = MariaTypes.point
val polygonType: MariaType<Polygon> = MariaTypes.polygon
val gcType: MariaType<GeometryCollection> = MariaTypes.geometrycollection

// Create a point
val p: Point = Point(1.0, 2.0)

Nullable Types

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

val notNull: MariaType<Int> = MariaTypes.int_
val nullable: MariaType<Int?> = MariaTypes.int_.opt()

Custom Domain Types

Wrap base types with custom Java types using transform:

// Wrapper type
data class UserId(val value: Long)

// Create MariaType from bigint
val userIdType: MariaType<UserId> = MariaTypes.bigint.transform(::UserId, UserId::value)