Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tiny int of MySQL to Integer in Java

I have an tiny int column in MySQL. I want to convert it into int type of java.

So if I mention the column in my hibernate entity as

@Column(name="Columname")
private int something;

Will it cause an error as tiny int needs boolean type or will it get cast into int?

This code will be changed in production Db hence I cannot check it to see if it breaks.

like image 692
Mayank_Thapliyal Avatar asked Oct 30 '25 07:10

Mayank_Thapliyal


2 Answers

JDBC driver maps databse type to java. So in case of mysql TINYINT will be converted to java.lang.Boolean or java.lang.Integer.

Refer this link which explains : Java, JDBC and MySQL Types

like image 54
PVR Avatar answered Oct 31 '25 19:10

PVR


Go for the datatype Byte. it worked for me!

like image 39
Vishal_Kotecha Avatar answered Oct 31 '25 20:10

Vishal_Kotecha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!