File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Displaying one to many records from DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Displaying one to many records from DB" Watch "Displaying one to many records from DB" New topic
Author

Displaying one to many records from DB

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 742
Hello,

There are many dept record in my db and each dept may have one or more than one record.
I am trying to fetch one dept and then to get this dept records that may be one or many. Please check this link that shows the wrong output whereas the expected output is at this Link

Here is my all code of the method


Thanks & best regards
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 742
Can anybody please help me to fix the problem?

Best regards
Bijesh Roy
Greenhorn

Joined: Jun 28, 2011
Posts: 8
Can you please try closing rs1? Looks like since you are not closing rs1 so previous department id's are also getting added next time....try closing rs1 once hopefully it will solve the issue.....

Please let me know the result.....
Bijesh Roy
Greenhorn

Joined: Jun 28, 2011
Posts: 8
close rs1 just after closing ps1....
Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

Since you are reusing the variable "m2" for both the departments, it is retaining the values of the first department and carried to the second department. Try to reinitialize the variable m2 after the iteration of the first department is over.

Regards
Santhosh
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 742
Dear Santhosh,

Thanks a lot. The problem fixed with initializing msg2 within while loop

Appreciated!!

Best regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying one to many records from DB