Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Multiple Tables

 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34686
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Bob Frapples
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic