Ways to save enums in database

Posted by corgrath on Stack Overflow See other posts from Stack Overflow or by corgrath
Published on 2008-10-23T14:11:15Z Indexed on 2010/04/14 14:53 UTC
Read the original article Hit count: 385

Filed under:
|
|
|
|

Hey guys.

I am wondering what the best ways to save enums into a database is.

I know there are name() and valueOf() methods to make it into a String back. But are there any other (flexible) options to store these values?

Is there a smart way to make them into unique numbers (ordinal() is not safe to use)?

Any comments and suggestions would be helpful :)

Update:

Thanks for all awesome and fast answers! It was as I suspected.

However a note to 'toolkit'; That is one way. The problem is that I would have to add the same methods with each enum type i create. Thats a lot of duplicated code and, at the moment, Java does not support any solutions to this (You cannot let enum extend other classes).

However, thanks for all answers!

© Stack Overflow or respective owner

Related posts about enums

Related posts about java