Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Logical Display Error

hi everyone,

Out put  of a Storage Procedures is something like this:
-------------------------------
Name            FileSize
------------------------------
Bat.exe           52344
Read.txt             413
Install.iso         1111
------------------------------

MY JSP CODE: (Correct my code to display how I wanted)
...
 while (rs.next()) {
     out.print("Install ISO:"+ rs.getString(1));
     out.print("<BR>");
     out.print("File Size:"+rs.getString(2));
     out.print("<BR>");
     out.print("Batch File:"+ rs.getString(1));
     out.print("<BR>");
     out.print("File Size:"+rs.getString(2));
     out.print("<BR>");
     out.print("Read Me File:"+ rs.getString(1));
     out.print("<BR>");
     out.print("File Size:"+rs.getString(2));
     out.print("<BR>");
....

the output I'm getting is
==========================
Install ISO:     Bat.exe          
File Size:        52344
Batch File:      Bat.exe
File Size:        52344
Read Me File: Bat.exe
File Size:       52344

Install ISO:     Read.txt          
File Size:        413
Batch File:      Read.txt
File Size:        413
Read Me File:  Read.txt
File Size:       413

Install ISO:     Install.iso          
File Size:         1111
Batch File:      Install.iso
File Size:         1111
Read Me File:  Install.iso
File Size:        1111

==========================
But I want the output in this way:
       
Install ISO:     Install.iso          
File Size:         1111
Batch File:      Bat.exe
File Size:         52344
Read Me File:  Read.txt
File Size:         413

Regards,
Hyd

0
princehyderabad
Asked:
princehyderabad
  • 3
  • 2
1 Solution
 
objectsCommented:
try:

if (rs.next())
{
     out.print("Install ISO:"+ rs.getString(1));
     out.print("<BR>");
     out.print("File Size:"+rs.getString(2));
     out.print("<BR>");
     if (rs.next())
     {
        out.print("Batch File:"+ rs.getString(1));
        out.print("<BR>");
        out.print("File Size:"+rs.getString(2));
        out.print("<BR>");
     }
     if (rs.next())
     {
        out.print("Read Me File:"+ rs.getString(1));
        out.print("<BR>");
        out.print("File Size:"+rs.getString(2));
        out.print("<BR>");
     }
   }
}

0
 
princehyderabadAuthor Commented:
Half the way ...

DB giving back the result set in this order:
Bat.exe        
Read.txt        
Install.iso      

Using your above code able to display correct, but my problem is I want to arrange the out in this order.
1. Install.iso
2. Bat.exe
3. Read.txt

0
 
objectsCommented:
maybe something like:

Map sizes = new HashMap();
while (rs.next())
{
   sizes.put(rs.getString(1), rs.getString(2));
}
out.print("Install ISO: Install.iso");
out.print("<BR>");
out.print("File Size:"+sizes.get("Install.iso"));
out.print("<BR>");
out.print("Batch File: Bat.exe");
out.print("<BR>");
out.print("File Size:"+sizes.get("Bat.exe"));
out.print("<BR>");
out.print("Read Me File: Read.txt");
out.print("<BR>");
out.print("File Size:"+sizes.get("Read.txt"));
out.print("<BR>");
0
Industry Leaders: 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!

 
princehyderabadAuthor Commented:
I didnt try your code this morning. but I have a Question, you are saying here:
sizes.get("Install.iso")
sizes.get("Batch.exe")
sizes.get("Read.txt")
But I dont know if DB will have  this names or others, it can be 'Installer.iso1' not necessary 'Install.iso'.

please explain..
0
 
KuldeepchaturvediCommented:
you  can add a "order by name" in your stored procedure so it returns the data in your required order and after than object's code can be used to display it.
0
 
objectsCommented:
> But I dont know if DB will have  this names or others, it can be 'Installer.iso1' not necessary 'Install.iso'.

Then how do you know what label to display for each row?
eg. which row is Inall ISO:, which row is Read Me File: etc
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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