2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MySQLデータ型とJava型の対応表

2
Last updated at Posted at 2025-04-02

MySQLデータベースとJavaアプリケーション間でデータをやり取りする際、データ型の整合性を保つことが非常に重要です。この記事では、こちらのリンクからの情報を基に、MySQLのデータ型と、それに対応するJavaのデータ型を「データを受け取る場合」と「パラメータを設定する場合」に分けて整理し、それぞれの適切なマッピングを紹介します。

サポートされているデータ型

データをResultSetから受け取る場合:

MySQL type Java type
date LocalDate
datetime LocalDateTime
new_date LocalDate
timestamp LocalDateTime
tinyint Byte
smallint Short
year Short
float Float
double Double
int24 Int
mediumint Int
bigint Long
numeric BigDecimal
new_decimal BigDecimal
decimal BigDecimal
string String
var_string String
varchar String
time java.util.Duration
text String
JSON String
enum String
blob ByteArray

PreparedStatementにパラメータを設定する場合:

Java type MySQL type
Byte tinyint
Short smallint
Int mediumint
Float float
Double double
BigDecimal decimal
LocalDate date
DateTime timestamp
java.util.Duration time
java.sql.Date date
java.util.Date timestamp
java.sql.Timestamp timestamp
java.sql.Time time
String string
ByteArray blob
java.nio.ByteBuffer blob
io.netty.buffer.ByteBuf blob
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?