wood burning stoves*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 732
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: 732
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: 732
Dear Santhosh,

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

Appreciated!!

Best regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Displaying one to many records from DB
 
Similar Threads
Showing resultSet
java.sql.SQLException: Closed Statement: next
Want to convert my code in method
In the messages module reply is not working
How can I generate dynamic tables taking values from database