This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes retriving two primary  keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "retriving two primary  keys" Watch "retriving two primary  keys" New topic
Author

retriving two primary keys

Shobana Sukumar
Greenhorn

Joined: Nov 24, 2005
Posts: 17
i need to work with a table which has two primary keys.

when i use DataBaseMetaData.getPrimaryKeys() i can extract the value if theres one primary key.but what if two primary keys are there.any suggestions?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Why can't you use DatabaseMetaData.getPrimaryKeys() to deal with a primary key that has two columns? It looks like this method returns a ResultSet. Have you checked how many rows are in this result set in the situation you describe? If it has multiple rows, then each row probably represents one column in the primary key.

HTH

Layne


Java API Documentation
The Java Tutorial
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Originally posted by Shobana Sukumar:
i need to work with a table which has two primary keys.



To be precise, that's impossible. A table can have only one primary key, that's the basic fundamental meaning of "primary". You can however, have a primary key composed of more than one column. A primary key is nothing more or less than a unique index with a very special (primary) relationship to the table; most databases implement it that way.

The previous response appears to be on the right track for "how do I work with a table which has a primary key with multiple columns?".
 
Don't get me started about those stupid light bulbs.
 
subject: retriving two primary keys