File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Finding the primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Finding the primary key" Watch "Finding the primary key" New topic
Author

Finding the primary key

Rik Sweeney
Ranch Hand

Joined: Sep 04, 2001
Posts: 36
I need to allow a user to perform joins on primary/foreign key pairs. Is there anyway I can find a foreign key in a table and it's matching primary key table? I really need the columns from both the tables aswell. Is there an easy way to do this?
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

DatabaseMetaData.getCrossReference should do the trick for you. If your driver does not implement this method then you might have to hit the database system tables to get the info which are database specific.
also DatabaseMetaData.getImportedKeys() and DatabaseMetaData.getExportedKeys() could be useful too.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding the primary key
 
Similar Threads
One to one mapping issue
modelling an association with entity beans
Can we make any column in nested table as foreign key of a normal table primary key?
Getting primary keys
updating primary key