Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP Report

Status
Not open for further replies.

crguy

Programmer
May 24, 2001
34
CA
Hi,

I am creating a report in JSP with Oracle backend.
My report needs to be displayed in a html table (this is not a problem).

Unfortunately, the first column repeats itself over and over again. Is there anyway to suppress duplicated values in JSP?

Thanks in advance.
VC
 
Do you want it to do with JSP only?
Why dont you get the Distinct values from the Data Base which is much quicker and the best way to avoid duplicates.

If you want it to do with JSP you can let me know.

Cheers
 
Hi,

Putting distinct will not help, as every row is distinct.
Thie is what happens:

Manager Joe Smith
Manager John James

This is what I would like:

Manager
Joe Smith
John James etc:

I would like to do this in JSP.

Thanks
 
Hi,

Hope this could help you in your report generation.

import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;

public class TestDup {

public static void main(String ars[]) {

// designations

Vector designation = new Vector();
designation.addElement("Manager");
designation.addElement("Manager");
designation.addElement("Clerk");
designation.addElement("Programmer");
designation.addElement("Programmer");
designation.addElement("Clerk");
designation.addElement("Programmer1");
designation.addElement("Programmer1");

// employee names

Vector empNames = new Vector();
empNames.addElement("Joe Smith");
empNames.addElement("John Smile");
empNames.addElement("John Raj");
empNames.addElement("Raj Kumar");
empNames.addElement("Raj Kumar2");
empNames.addElement("Vijay");
empNames.addElement("Raj Kumar3");
empNames.addElement("Raj Kumar4");

// contains Designations and names of the employees

Hashtable desigNames = new Hashtable();

for (int i = 0; i < designation.size(); i++) {
String orgVal = designation.get(i).toString();
Vector vector = null;
if (desigNames.containsKey(orgVal)) {
vector = (Vector) desigNames.get(orgVal);
vector.addElement(empNames.get(i));

} else {
vector = new Vector();
vector.addElement(empNames.get(i));
desigNames.put(orgVal, vector);
}
}

Enumeration enumeration = desigNames.keys();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement().toString();
System.out.println(&quot;Designation&quot; + key);
Vector names = (Vector) desigNames.get(key);
System.out.println(&quot;Emp Name &quot; + names);
}
}

}

The output would be like this

Designation |Programmer1|
Emp Names |[Raj Kumar3, Raj Kumar4]|
Designation |Manager|
Emp Names |[Joe Smith, John Smile]|
Designation |Clerk|
Emp Names |[John Raj, Vijay]|
Designation |Programmer|
Emp Names |[Raj Kumar, Raj Kumar2]|

Let me know.

Cheers
venu

 
Hi,

How can I pick up these values dynamically?
Vector designation = new Vector();
designation.addElement(&quot;Manager&quot;);
designation.addElement(&quot;Manager&quot;);
designation.addElement(&quot;Clerk&quot;);
designation.addElement(&quot;Programmer&quot;);
designation.addElement(&quot;Programmer&quot;);
designation.addElement(&quot;Clerk&quot;);
designation.addElement(&quot;Programmer1&quot;);
designation.addElement(&quot;Programmer1&quot;);

VC
 
Hi,

I assume that you are reading these values from DB. So you have the result set.

Ex:

String sqlString = &quot;select designation, name from emp&quot;;

Result of the above query would be some thing like this

Designation Name
------------------------------
Manager Joe Smith
Manager John Smile
Clerk John Raj
Programmer Raj Kumar
Programmer Raj Kumar2
Clerk Vijay
Programmer1 Raj Kumar3
Programmer1 Raj Kumar4

stmt = conn.createStatement();
rs = stmt.executeQuery(sqlString);
Vector designation = new Vector();
Vector empNames = new Vector();
while(rs.next())
{
designation.addElement(rs.getString(1).toString());
empNames.addElement(rs.getString(2).toString());
}
stmt.close();

This should help you.

Cheers,
venu
 
Hi,

Sorry for all the questions. After modifying the code as you suggested I get an &quot;Incompatible type for method. Can't convert java.util.Vector to java.lang.String&quot;

Any suggestions? I will look on the net for examples.
Thanks for your help.

VC
 
I think you are getting the Error at this statement.

Enumeration enumeration = desigNames.keys();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement().toString();
System.out.println(&quot;Designation&quot; + key);
Vector names = (Vector) desigNames.get(key);
System.out.println(&quot;Emp Name &quot; + names);
}

Names is a Vector. If you need to read the values in the vector you need to loop through it.

Enumeration enumeration = desigNames.keys();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement().toString();
System.out.println(&quot;Designation&quot; + key);
Vector names = (Vector) desigNames.get(key);

for(int i=0; i< names.size(); i++)
{
String orgName = names.elementAt(i).toString();
// now you have name in the orgName
System.out.println(orgName);
}

}


let me know. If not just paste your code, that would help me.
Cheers
venu
 
Hi,

Thank you I think that did the trick.

VC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top