If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Having problem with retieving the primary keys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-16-09, 16:54
swati malla swati malla is offline
Registered User
 
Join Date: Jul 2009
Posts: 26
Having problem with retieving the primary keys

Hello Everyone,
I am having a problem with retrieving the primary keys of a table by using JDBC.
This is the code looks like

DatabaseMetaData data=con.getMetaData();
ResultSet primarykey=data.getPrimaryKeys(con.getCatalog(),sc hemaname, tableName);

primarykey.next() //which is returning a false.
but the table has a primary key.
Is there any other way to retrieve the primary key....

i would really appreciate if some one can reply me back.

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 07-16-09, 17:02
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I think somebody has already referred you to the manual describing the DB2 system catalog views. May be it's time to read it...
Reply With Quote
  #3 (permalink)  
Old 07-17-09, 03:20
aflorin27 aflorin27 is offline
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
Here are the system catalog views:
DB2 Database for Linux, UNIX, and Windows

and this is the view you need to query from:
DB2 Database for Linux, UNIX, and Windows
__________________
Florin Aparaschivei
Iasi, Romania
Reply With Quote
  #4 (permalink)  
Old 07-17-09, 11:24
swati malla swati malla is offline
Registered User
 
Join Date: Jul 2009
Posts: 26
Hello thanks a lot this answer helped me a lot because you gave me a specific one to look one more time thanks a lot......
I have used the following query may be in future for some one it might be useful..
"select t.TABSCHEMA,t.TABNAME, k.colseq, k.colname from syscat.keycoluse k, syscat.tabconst t where k.constname = t.constname and k.tabname = t.tabname and k.TABSCHEMA = t.TABSCHEMA and t.type='P'and t.TABSCHEMA NOT LIKE 'SYS%'";

Which eliminates the system tables and gets the all the primary keys....

Thanks,
swati
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On