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.decimal(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_(10)
val varcharType: MariaType<String> = MariaTypes.varchar(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.binary(16)
val varbinaryType: MariaType<ByteArray> = MariaTypes.varbinary(255)
val blobType: MariaType<ByteArray> = MariaTypes.blob

Date/Time Types

MariaDB TypeJava TypeNotes
DATELocalDateDate only
TIMELocalTimeTime only
DATETIMELocalDateTimeDate and time
TIMESTAMPLocalDateTimeWith auto-update
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.time(6)
val dtFsp: MariaType<LocalDateTime> = MariaTypes.datetime(3)

ENUM Type

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

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

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")

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)