• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the best way for store registers

 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a sql query where I must extract the registers of two columns. Then I must do different operations with them in some pieces of code.
I would like to know how is the best way to store these registers.
Should I store in arraylist, in a class, in a class with two strings and then create an arraylist with the class?
Many thanks and sorry for my english!

 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not understand your question can you explain in detail?
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ninad Kulkarni wrote:I did not understand your question can you explain in detail?

Sorry my English is very bad.

Of a sql statement I extract two fields (duration and date).
I would like to store these two filed to then I can manipulate it.
I must pass these values inside different methods and classes and then when I manipulate them then I must return in a method of a class. So how I can't return two arraylist and I'am learning Java I would like the proper way to make these.

Thanks and sorry for my English again
 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual way would be (as you suggest in your first post) to create a Class that represents your data.
So in your case a class with two fields, one for duration and one for date, and create a List of that which is what you would do your processing on.
 
Junilu Lacar
Bartender
Pie
Posts: 8786
81
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is where the concept of ORM comes in - Object-Relational-Mapping. You want to separate the concepts of how data is logically related from the way it is persistently stored in a database. The usual approach is this:

1. In your persistence layer, use a DAO (Data Access Object):
1a. Query the database for the data
1b. Go through the resultset
1c. For each row in the resultset, create an object that encapsulates the data
1d. Put each object that you created this way into a container, usually a List
1e. When you have processed everything in the resultset, return the List<yourObject>

NOTE: The DAO API should declare List<yourObject> rather than ArrayList<yourObject>.

2. In your Business Layer code
2a. Get a List<yourObject> from the DAO
2b. Work with the List as required. You can iterate through the list and work with each object in turn, or you can work with the list as whole and do operations like search, sort, etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic