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

    Unanswered: Having problem with tretrieving table names

    Hello Everyone,
    I am new to DB2.I have couple of questions.
    Before to my question.I am using DB2 type 4 driver.(db2jccjar).
    I have a data base and trying to retrieve all the table names under the data base from java client.
    I have used the following code.

    Statement stmt = con.createStatement();
    String query="list database directory show detail";
    stmt.execute(query);
    But it throws me an exception as follows.
    DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=END-OF-STATEMENT;irectory show detail;JOIN <joined_table>,
    I would really appreciate if some one can help me out for this question.
    Thanks in advace.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    "LIST DATABASE DIRECTORY" lists, well, databases, not tables. Besides, it is not an SQL statement but rather a CLP command, so you cannot execute it via JDBC.

    The best way to obtain the list of tables is by using a java.sql.DatabaseMetaData.getColumns() call. If you must query the database, the information you are looking for is in the SYSCAT.TABLES table.
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Jul 2009
    Posts
    26
    Thanks a lot for your quick response.Yes you are correct i wanted to execute from JDBC .Can you please explain little bit about SYSCAT.TABLES??????
    I would really appreciate if you can send me a reply....

  4. #4
    Join Date
    Jul 2009
    Posts
    26
    Thanks a lot for your quick response.Yes you are correct i wanted to execute from JDBC .Can you please explain little bit about SYSCAT.TABLES??????
    I would really appreciate if you can send me a reply....

  5. #5
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    A little bit (and a lot) about SYSCAT.TABLES is written in the fine DB2 SQL Reference manual, a link to which you can find in the sticky post at the top of this fine forum.
    ---
    "It does not work" is not a valid problem statement.

  6. #6
    Join Date
    Jul 2009
    Posts
    26
    Hello,
    Thanks for your response.I was trying to use java.sql.DatabaseMetaData.getColumns(); Hopefully which will return all the table names to me.But for execute this i need to give the following input such as 1)catalog2)schemaPattern3)tableNamePattern4)column NamePattern.I don't understand any of these.I don't know the table names and how many tables are there.
    I would really appreciate if some one can give me a response back.....

  7. #7
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    the first thing todo would be to study some basics about any relational database. this is common for all
    schema tablename columnname or see the help
    SYSCAT.TABLES catalog view
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

Posting Permissions

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