jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes Accessing Multiple Tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Accessing Multiple Tables" Watch "Accessing Multiple Tables" New topic

Accessing Multiple Tables

Chase Becicka

Joined: Feb 16, 2004
Posts: 23
I just have a quick question with connecting to multiple tables, This is the first time I have attempted to code with a database cotaining multiple tables, is there anything special I need to do access the second table within my database or can I still just throw out the column name to connect to the resultset in that table
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

The first thing is to make sure you have a condition in your web clause to join the tables. Otherwise, you will get every combination of rows from both tables.

If the column names are all distinct, you can still use the column name as is to get the result. If not, you can use a column number or an "as statement." For example:

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bob Frapples
Ranch Hand

Joined: Mar 08, 2002
Posts: 32
you can access both tables the same way, and deal with the data in your app, this is no different than dealing with multiple Java objects, conceptually

or you can use a join statement and have one single ResultSet, thus one object returned yet multiple tables are searched
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63839

"Brackish Water",

Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Forum Bartender

[Asking smart questions] [About Bear] [Books by Bear]
Chase Becicka

Joined: Feb 16, 2004
Posts: 23
Well my data tables do have one common column, its set up like this,

my custNum is a column on both tables I have and the second table cannot exsist without a mathcing value in the first table so the CustNum links the two tables togeather and is the primary key for both tables
I agree. Here's the link: http://aspose.com/file-tools
subject: Accessing Multiple Tables
It's not a secret anymore!