This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes Accessing Multiple Tables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Accessing Multiple Tables" Watch "Accessing Multiple Tables" New topic
Author

Accessing Multiple Tables

Chase Becicka
Greenhorn

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 26192
    
  66

Chase,
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:


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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
Marshal

Joined: Jan 10, 2002
Posts: 56202
    
  13

"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.

Thanks!
bear
Forum Bartender


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Chase Becicka
Greenhorn

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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Accessing Multiple Tables
 
Similar Threads
Designing Table specific DAO
Multiple tables or single table
can i use one entity bean to access more than one tables
Connecting to Multiple Schemas
Pass JPA entities across tiers?