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 retriving two primary  keys 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 "retriving two primary  keys" Watch "retriving two primary  keys" New topic

retriving two primary keys

Shobana Sukumar

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.



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?".
I agree. Here's the link:
subject: retriving two primary keys
jQuery in Action, 3rd edition