Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8764675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:05:39+00:00 2026-06-13T16:05:39+00:00

I’ve built a JavaEE project and need to store the gender of a user

  • 0

I’ve built a JavaEE project and need to store the gender of a user in MySQL. And I want to show this property when adding a new user account. For example

<select name="gender">
    <option value="0">Male</option>
    <option value="1">Female</option>
</select>

Now I’ve found 2 approaches to store this property in MySQL.

  1. use integer/char to store gender column:

    gender tinyint(1) not null;
    

    in this case, I have to write these in my Java code:

    public class StaticData {
        public static final short MALE = 0;
        public static final short FEMALE = 1;
    }
    

    If so, my database will depend on my Java code to limit the value range and explain what 0/1 represents (low level depends on high level). I think that’s not a good idea.

  2. use an enum to store gender column:

    gender enum("MALE", "FEMALE") not null
    

    and in this case, my Java code will depend on the enum’s value. There are 2 ways to get these values:

    1) public enum Gender { MALE, FEMALE }, it’s nearly the same problem as with method 1.

    2) retrieve these values from MySQL, such as “SHOW COLUMNS FROM user LIKE \”gender\”” and then use a regular expression to split the string. But this is a verbose method. And have to query from db everytime I load a JSP. I think it would be expensive.

Is there a common idiom for this? If not, what factors do I need to consider when choosing the appropriate solution for my project?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:05:40+00:00Added an answer on June 13, 2026 at 4:05 pm

    I would make a Table “Gender” with an id as key and the Text wich should be shown to the user:

    • ID – Text
    • 1 – Male
    • 2 – Female

    In the Person you save the gender-ID as foreign key.

    When you want to show the person you join can join the gender to the person and print the text out.
    For the select control you select all rows in the gender table and generate the html with the rows.

    If there is a new gender to support, you just add it in the database, no java code must be edited…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.