• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic