What is the best implementation for boolean in MySQL using Java to connect to the database?

I currently have a MySQL database installed with a Java client that accesses and uses the database. I need a Boolean data type in a database to determine if certain actions are allowed by different database users. What is the best boolean implementation you can use in MySQL since there is no Boolean data type?

I know that TinyInt can be used with PreparedStatement with setByte(int parameterIndex, byte x , and I also know that Bit can also be used with setBoolean(int parameterIndex, boolean x) . Which one is the best solution for a Boolean value? And if is there a better solution, what would it be?

+7
source share
2 answers

MySQL's Boolean is synonymous with TINYINT(1) ; Bit also if the number of bits is small enough. From the point of view of MySQL, this has little effect on what you use. What does "better" mean?

+6
source

It is assumed that you cannot access MySQL BOOL using JDBC setBoolean - you can. So the best option is to declare the column as BOOL and use setBoolean . Although MySQL will TINYINT your TINYINT declaration, your SQL will declare what you want to use, and your Java code also makes it obvious at this level.

+1
source

All Articles