Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database fields to java class

 
Timothy Resh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic