I currently have a MySQL database set up with a Java client accessing and using the database. I need a Boolean data type in the database to determine whether some actions are allowed by various users of the database. What is the best implementation of Boolean that you can use in MySQL since there is no Boolean data type?
I know that TinyInt
can be used with a PreparedStatement
with setByte(int parameterIndex, byte x
and I also know that Bit
can also be used with setBoolean(int parameterIndex, boolean x)
. Which of these is the better solution for a Boolean value? And if there is a better solution, what would it be?
Boolean
in MySQL is a synonym for TINYINT(1)
; Bit
is, as well, if the number of bits is small enough. From the point of view of MySQL operation, it makes little difference which you use. What do you mean by "better"?
You seem to be assuming that you can't address MySQL's BOOL
using JDBC's setBoolean
- you can. As such, the best option is to declare the column as BOOL
and use setBoolean
. Even though MySQL will alias your declaration to a TINYINT
, your SQL declares what you want to use and your Java code makes it obvious at that level too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.