• 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

Database fields to java class

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all, I'm new to java. Here is my problem. I have a servlet which retrieves data from a database (multi row data retrieved per select)and puts the data into a hash table via row column map ex.... 1-8=Client account. Where 1 is row and 8 is the column. This works but is not very descriptive unless you know the column number to database field name relationship ( so much for good naming conventions). The question is what other way can I store the data and keep the column name and it's attributes so I can pass it along to other classes. Basically I want a resultset that does not maintain a database connection. Another reason I need this separation is so I can use connection pooling for less overhead and faster connection establishment.
I have looked at a few different ways but I am lost. I need the short version of a dummys guide and a few hints from the vast experience everyone has here.
Thanks
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Timothy,
Welcome to Javaranch!
It's clearer to create an object representing the row of data. Each field would have a meaningful name. If you don't want to do that, you could use the column name as a key in your hash table.
 
Timothy Resh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes sense. Is their a way to index the objects or do I use an array list of objects and just search through the array via a for statement? Do you know of any database to object mappers that are any good? I assume we are talking jdo here.
Thanks
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do it either way: an ArrayList or Hashmap (if you have a meaningful key.) If you want to know more about JDO, the forum one down (object relational mapping) is great.
reply
    Bookmark Topic Watch Topic
  • New Topic