Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

retriving two primary keys

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?".
 
Hold that thought. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic