Documentation Home
MySQL Cluster API Developer Guide
Download this Manual
PDF (US Ltr) - 4.9Mb
PDF (A4) - 4.8Mb
EPUB - 1.9Mb
HTML Download (TGZ) - 1.8Mb
HTML Download (Zip) - 1.9Mb


MySQL Cluster API Developer Guide  /  ...  /  ClusterJ Mappings Between MySQL and Java Data Types

4.2.2.5 ClusterJ Mappings Between MySQL and Java Data Types

ClusterJ provides mappings for all of the common MySQL database types to Java types. Java object wrappers of primitive types should be mapped to nullable database columns.

Note

Since Java does not have native unsigned data types, UNSIGNED columns should be avoided in table schemas if possible.

Compatibility with JDBC mappings.  ClusterJ is implemented so as to be bug-compatible with the JDBC driver in terms of mapping from Java types to the database. That is, if you use ClusterJ to store or retrieve data, you obtain the same value as if you used the JDBC driver directly or through JPA.

The following tables show the mappings used by ClusterJ between common Java data types and MySQL column types. Separate tables are provided for numeric, floating-point, and variable-width types.

Numeric types.  This table shows the ClusterJ mappings between Java numeric data types and MySQL column types:

Java Data Type MySQL Column Type
boolean, Boolean BIT(1)
byte, Byte BIT(1) to BIT(8), TINYINT
short, Short BIT(1) to BIT(16), SMALLINT, YEAR
int, Integer BIT(1) to BIT(32), INT
long, Long BIT(1) to BIT(64), BIGINT, BIGINT UNSIGNED
float, Float FLOAT
double, Double DOUBLE
java.math.BigDecimal NUMERIC, DECIMAL
java.math.BigInteger NUMERIC (precision = 0), DECIMAL (precision = 0)

Date and time types.  The following table shows the ClusterJ mappings between Java date and time data types and MySQL column types:

Note

ClusterJ maps the MySQL YEAR type to a Java short (or java.lang.Short), as shown in the first table in this section.

java.util.Date represents date and time similar to the way in which Unix does so, but with more precision and a larger range. Where Unix represents a point in time as a 32-bit signed number of seconds since the Unix Epoch (01 January 1970), Java uses a 64-bit signed number of milliseconds since the Epoch.

Variable-width types.  The following table shows the ClusterJ mappings between Java data types and MySQL variable-width column types:

Java Data Type MySQL Column Type
String CHAR, VARCHAR, TEXT
byte[] BINARY, VARBINARY, BLOB
Note

No translation binary data is performed when mapping from MySQL BINARY, VARBINARY, or BLOB column values to Java byte arrays. Data is presented to the application exactly as it is stored.


User Comments
Sign Up Login You must be logged in to post a comment.