Two Laptop Bag*
The moose likes JDBC and the fly likes Basic question about a sql select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Basic question about a sql select" Watch "Basic question about a sql select" New topic
Author

Basic question about a sql select

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
Hello,

I have a single table that contains redundant data and that really should have been modelled as several tables and unfortunately I have to make do with it.

The data is as follows:



I am looking for the best way to use those data and display and structure it as follows (in html or xml):



What is the best way to solve that problem bearing in mind I use SQL and Java.

Thanks in advance,

Julien.
Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
Hi Julien,

I think you need to display the Data in the format you had shown. Create a Model in java like this,



1. Write an DAO Class in which you query all the records from the table.
2. Get the first Resultset.Create an HashMap with key as personId and value as Order Model.
3. Get the personId for next value resultset, check if the person id is present in the HashMap, if yes the get the Order Model for that id and update the OrderDetails.If not create a new order model and update the
Hashmap with the new Personid.
4. Do the same all the values in resultset.
5. Atlast Return the hashmap from DAO. Use it to build xml or display in html.

Hope this Helps.

Thanks,
Arul.
Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
thanks a lot for your reply!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic question about a sql select
 
Similar Threads
suggetion needed
Retrieving xm from mySQL and sending it through webservice method
Advantages of ORM?
To get DB column names dynamically at run time.
Avoiding java code generate HTML pages