aspose file tools*
The moose likes JDBC and the fly likes Database fields to java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database fields to java class" Watch "Database fields to java class" New topic
Author

Database fields to java class

Timothy Resh
Greenhorn

Joined: May 08, 2004
Posts: 3
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


Timothy M Resh
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Timothy Resh
Greenhorn

Joined: May 08, 2004
Posts: 3
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database fields to java class
 
Similar Threads
Updating Database by editing jtable
Invoking ODBC database source administrator component of windows
Updating Database by editing jtable
JSP column name hyperlink help
Need a disconnected resultset