File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Displaying records from multiple table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Displaying records from multiple table" Watch "Displaying records from multiple table" New topic

Displaying records from multiple table

Bashar Ayyash
Ranch Hand

Joined: Jun 24, 2004
Posts: 44
Hi Guys,

I need your help to display records from multiple tables (tbl_users, tbl_dependants), I want to display user information in one row and user dependants in a column after ending user information, the two tables are related with (user_id). When the first user recordSet finishs displaying all user information + his dependants, it goes to the next line and print another user details,,, and so on.

I searched the entire forum for a help but I couldn't find.

Best Regards,
[ January 05, 2006: Message edited by: Bear Bibeault ]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

What part are you having trouble with, the SQL, parsing the results?
What have you got so far?

There are a lot of ways to get from the database to the browser.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bashar Ayyash
Ranch Hand

Joined: Jun 24, 2004
Posts: 44
I got so far, one row of user details + his dependants and a second row of another user details but without his dependants.

there is a little thing I must do but I couldn't figure it.

thanx for the help,
Matt Gatten

Joined: Oct 29, 2005
Posts: 7
Your SQL statement could be written like this:

Hope that helps. They are called joins and you should read up on them.

You could also query all the names from the 1st table, loop through them and on each loop query for the dependents associated with that users name. That's not a very efficient way to do it, however.
[ January 05, 2006: Message edited by: Matt Gatten ]
I agree. Here's the link:
subject: Displaying records from multiple table
It's not a secret anymore!