[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

Display Format


I need a suggestion and idea how to format my display data which is coming from DB.  MY JSP page is combination of two DB tables.

1st Table Returns:
Family   Product  Version Avaiable  Description  Released-Date
ABC       xx          1.0        Yes       Blah....          04/20/05
ABC       xx           2.0        Yes       Blah....          04/10/05
XYZ       dd           4.5        Yes       Blah....          05/10/05
XYZ       ii             5.5        No       Blah....           05/12/05

2nd Table Returns:
Family   Product  Version   Filenames
ABC       xx          1.0         V1install.exe, Vreadme.txt
ABC       xx           2.0         Xinstall.exe, Xreadme.txt, patch.exe
XYZ       dd           4.5        Dinstall.exe, Dreadme.txt
XYZ       ii             5.5        Iinstall.exe, Ireadme.txt, exc.bat

I have 2 different stored procedure from which I get above two tables data. Now I dont know how to display this ?

Conserding 1st table: ResultSet rs1
                 2nd Table: ResultSet rs2.
Sample code would be good.

  • 2
  • 2
  • 2
2 Solutions
One way of doing it would be like this.This is just my idea you can change it according to your requirements once you get he list of objects.
1>Create a 2 java class .First class will have all the attributes from the first table.Second java class will have all the attributes from the second table. When you retrieve the data from the first result set for every row you will create an object of class 1 and fill the attributes with the values from the result set. and add the object to a list.so by the end of the result set you will have a list of class 1 objects where each object is a row of the table.Similarly you can do the samething for the class 2.
2>By the end of this you will be having two list one list with the objects of class 1 and the second list with the objects of class 2.

3>You can traverse through both the list and compare the family,product and version if they are same then you can get the filenames from the other correspondign object and print the pattern will be something like this

Family   Product  Version Avaiable  Description  Released-Date  FileNames
ABC       xx          1.0        Yes       Blah....          04/20/05        V1install.exe, Vreadme.txt
ABC       xx           2.0        Yes       Blah....          04/10/05       Xinstall.exe, Xreadme.txt, patch.exe
XYZ       dd           4.5        Yes       Blah....          05/10/05       Dinstall.exe, Dreadme.txt
XYZ       ii             5.5        No       Blah....           05/12/05        Iinstall.exe, Ireadme.txt, exc.bat

princehyderabadAuthor Commented:
Well my records will be in 100's
Do you think it make sense to display Family "ABC" 100 times as well Product "xx" times... etc.,

It is up to you to decide how you want to present the data to the user
If the requirement is to display the tables values exactly as they are then "YES" you have to display family and product even though it has duplicates

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Well if it does not make sense to display the same data again and again u can use this logic.

1. Use hashTable for "File names".

   The key will be     ---> Family_name+"|"+Product+"|"+Version
   The values of the key                      -> will be set of ur FileNames

(Ex: Hashtable hash = new Hashtable(); hash.put(rS2.getFamily()+"|"+rS2.getProduct()+"|"+rS2.getVersion(),rS2.getFileNames()); where rS2 is ur second result set.)

2. Display part can be in this way ,

One table
   -> 1st row (header)
   -> 2nd row (data)
Each row
   -> 7 Columns (Family   Product  Version Avaiable  Description  Released-Date  FileNames)

Last column Should be displayed in a very nice fashion without actually displaying the data of all but last column)

When u come to last column,
 Open a new table -> Collect all the information necessary for the display of the Key Family_name+"|"+Product+"|"+Version and Keep this entire new Table inside a DIV tag

You can put a Plus and minus images. On click of the plus image, make the image as minus ....
 and enable the Div there by showing the actual contents of the Family,product, version ----

<div id=searchFilter1 style="display:''">
   <table ..............
      data of last column

enabling and disabling of the Table can be done using the following javascript.

                  function showHideFilter(i)
                        if (eval('searchFilter'+i+'.style.display == "none"'))
                              eval('searchFilter'+i+'.style.display = ""');
                              eval('document.images["filterImg'+i+'"].src = "../../images/minus.gif"');            
                              eval('document.images["filterImg'+i+'"].alt = "Hide Filter Panel"');                              
                              eval('searchFilter'+i+'.style.display = "none"');
                              eval('document.images["filterImg'+i+'"].src = "../../images/plus.gif"');
                              eval('document.images["filterImg'+i+'"].alt = "Show Filter Panel"');

Image can be kept like this

<IMG id="filterImg1" align=absmiddle border=0   style="cursor:hand" onClick = "javaScript:showHideFilter(1)" src="../images/plus.gif">
princehyderabadAuthor Commented:
Well arun99907 I agree with you but I need more help in this regards.

Actulay I'm using three different Stored Procedures to get information and using all 3 tables I need to display info as you said. So can I have a little sample code please.

1st Stored Procedures: (4 coloumbs)
Family, Product, Avaialable, Desc
eg: (XXX, x12, Yes, blah...)

2nd Stored Procedures: (6 coloumbs)
Family, Product, Version, Avaialable, Desc,  Release-Date
eg: (XXX, x12, 1.0, Yes, blah.., 04/04/05)

3rd Stored Procedures: (4 coloumbs)
Family, Product, Version, FileNames
eg: (XXX, x12, 1.0, file1.bat)
      (XXX, x12, 1.0, file2.exe)
      (XXX, x12, 1.0, file3.txt)

In 1st SP 'Available' is for Product. Whether Prodcut is available Yes or No.
In 2nd SP 'Available' is for Version. Whether Version is available Yes or No.

Thanks for your time.
hyd prince ;)

 Well i am not sure how u are getting ur data.

Assume ur data is in three result sets.

ResultSet Rs1
ResultSet Rs2
ResultSet Rs3

//  you can keep all the resultant ResultSets into Vector1, vector2, vector3 each holding the Data Objects (Set of Beans - setters and getters - added to vector1, vector2 vector3)

In your query order by Family, Product, Version such that Same set of family, product and version occur in a unique place of records.

 Construct a hashtable of "FileNames" for say 3rd procedure.

HashMap hash = new HashMap();
    String key = Rs3.getString("Family")+"|"+Rs3.getString("Product") +"|+Rs3.getString("Version");

/// At the end of this loop u will have a hashMap containing

 For each set of keys Say,
  Family1, Product1, 1.0Version - file1.txt
  Family1, Product2, 1.0Version - file2.txt
  Family1, Product2, 1.0Version - file3.txt

Now when you construct a key,
 it will be Key "Family1|Product1|1.0Version" and its corresponding value will be "file1.txt, file2.txt, file3.txt"

hash.get("Family1|Product1|1.0Version"); will return u "file1.txt, file2.txt, file3.txt"

You can construct such hash tables. for all kinds of repetetive rows.

In the case of 6 columns, Say if ur primary Key is 3 columns then create 3 hash Maps
1 hash map for column 4 data values (corresponding to first 3 columns formed keys)
1 hash map for column 5 data values (corresponding to first 3 columns formed keys)
1 hash map for column 6 data values (corresponding to first 3 columns formed keys)

At the end,
 You can write a for loop for all the sets of (Keys) data you want to display... and get corresponding key values hash.get(key); hash1.get(key); hash2.get(key); hash3.get(key); hash4.get(key); from the hash and display them inside a table....

I hope u got my logic ?

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now