• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Enum to Static Database Table  RSS feed

 
Niall Loughnane
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have a java enum Country with fields shortName and longName but i want to move the enum to a static database table,
What is the best way to achieve this?

The Country enum is:


Thanks in Advance,

Niall
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niall, you've (probably accidentally) checked the "Disable BB Code in this message" checkbox in your post. I've edited your post to uncheck it so that the code tags would be applied.

It is obviously not possible to use enum if the source of the data is in the database. You could create a class that would represent individual entries from the table and populate it using JDBC. Perhaps JPA or other ORM framework could be quite useful here.

If the table is really static, you might perhaps automatically generate the source code of the enum from the database table. Whether this is usable for you is hard to say; I'm using this approach in one project, in which some entries from the table are always known to be there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!