Currently I have a fairly large SQL table. Half way through it is an integer
field that I'm using to represent 5 checkboxes on a JSP form. The reason I
used a single INTEGER instead of many BIT fields is I could well be adding
more checkboxes later, and I don't really want to see the new fields
somewhere other than next to the 5 existing ones.
Now I started to doubt this approach when I realised that Sun's EL for JSP
pages doesn't cater for the bit operators. The following won't compile:
<c:if test="${(myflags & 0x01) == 0x01}">
So to get around this I have to just use a scriplet, i.e.:
<c:if test="<%= (myflags & 0x01) == 0x01 %>">
It still leaves a bad taste in my mouth though and makes me wonder if
there's a better approach, so I'm asking for advice here. Maybe I shouldn't
get attached to having the SQL look nice and ordered, in favour of more
readability in the Java? (Incidently, the 0x01 shown here is represented by
a static constant in my code for readability).
David Green - 16 Aug 2007 03:24 GMT
I think I answered my own problem by just writing it out.
I think I'll use SQL BIT types, which means I might end up in the sad
situation of an SQL table like:
NAME
AGE
FLAG_A
FLAG_B
FLAG_C
FLAG_D
FLAG_E
OCCUPATION
FLAG_F
with flag_f on its lonesome.. but I think it's worth it to avoid bit
manipulation in the Java.