This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the Keys in a Resultset

 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Good Day...

I want to write a function that will determine what are the keys of a particular table.

I have a query string that will use "select * from @table_name" where @table_name is determined at runtime.

Given the resultset from this query string, i need to determine which is the primary keys in this table. Is it possible to know this?

I googled for some answer and found the class ResultSetMetaData which is useful to some extent to determine the properties of each columns but this does not answer all my needs.

Please advice if I could accomplish this. Thanks.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4008
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many databases of meta data tables that you can query. Think of it as tables about tables. The format/storage of them is non-standard though so check your specific database system documentation.
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott,

Thanks for the reply..

I forgot to mention in my post that we are connecting to the database by remote and have limited access on system database tables that holds the data about the tables.

We are just given a set or a list of tables that we need to query to determine its Keys and display it. So I started looking up at the Java API for this but the class ResultSetMetaData was the one I found out. Unfortunately theres no method that would return if the column is a key or part of the keys.

Perhaps there's no workaround for this but to ask the DB Admin to give me access on these tables. Thanks again.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4008
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would the user of the system ever need to know about key relationships in the database? Better yet, why would they be likely to change? Sounds a web database anti-pattern to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic