• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Enum to Static Database Table

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic