Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    26

    Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    I think somebody has already referred you to the manual describing the DB2 system catalog views. May be it's time to read it...
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    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
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •