aspose file tools*
The moose likes Beginning Java and the fly likes Servlet Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Servlet Problem" Watch "Servlet Problem" New topic
Author

Servlet Problem

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
<blockquote>code:
<pre name="code" class="core">String query2="select a.p_id,s_id,specialty from position a, specialty b where a.p_id=b.p_id";

PreparedStatement ps2=cnn.prepareStatement(query2);
rs=ps2.executeQuery();
while(rs.next()){
String p_id=rs.getString(1);
String s_id=rs.getString(2);
String specialty=rs.getString(3);
out.println("store["+p_id+"] = new Array('"+specialty+"','"+s_id+"');");
}
ps2.close();
</pre>
</blockquote>


OUTPUT IS:
===========
store[1] = new Array('Cardiologist','1');
store[1] = new Array('Dermatologist','2');
store[1] = new Array('Urologist','3');
store[2] = new Array('CEO','4');
store[2] = new Array('COO','5');
store[3] = new Array('Cardiac Nurse','6');
store[3] = new Array('ss Nurse','7');
store[4] = new Array('Xray Technician','8');
store[4] = new Array('ECG Tech','9');


WHEREAS I WANT TO OUTPUT LIKE:
================================
store[1] = new Array('Cardiologist','1','Dermatologist','2','Urologist','3');
store[2] = new Array('CEO','4','COO','5');
store[3] = new Array('Cardiac Nurse','6','ss Nurse','7');
store[4] = new Array('Xray Technician','8','ECG Tech','9');




MY TABLE STRUCTURE
===================
SQL> desc position
Name Null? Type
----------------------------------------------- -------- --------------------------------
P_ID NOT NULL NUMBER(14)
POSITION VARCHAR2(104)

SQL> desc specialty
Name Null? Type
----------------------------------------------- -------- --------------------------------
S_ID NOT NULL NUMBER(14)
P_ID NUMBER(14)
SPECIALTY VARCHAR2(140)

[edit]Add code tags. CR[/edit]
[ July 17, 2008: Message edited by: Campbell Ritchie ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

This really has nothing to do with Servlets, or even JDBC, but rather basic algorithms, so I've moved it along to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
So you want to group output by specialty groups. Is there anything in your tables which allows such grouping? Yes there is, there is p_id. An "order by" clause in the query would help get them together.

You are going to have to work out some way of adding names of specialties.

How about adding them to Lists and printing out the Lists, based on the p_id numbers? Or using a StringBuilder and adding the names until the p_id changes.

By the way, your identifiers are difficult to read, "p_id" and "s_id" don't tell the reader what they are supposed to mean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Problem
 
Similar Threads
need some major help from you PLEASE
Null Values
Nested Record sets and Joins
how to bring variable from previous session to next session
Arrays