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 tretrieving table names

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-10-09, 13:20
swati malla swati malla is offline
Registered User
 
Join Date: Jul 2009
Posts: 26
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.
Reply With Quote
  #2 (permalink)  
Old 07-10-09, 13:34
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
"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.
Reply With Quote
  #3 (permalink)  
Old 07-10-09, 13:45
swati malla swati malla is offline
Registered User
 
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....
Reply With Quote
  #4 (permalink)  
Old 07-10-09, 13:45
swati malla swati malla is offline
Registered User
 
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....
Reply With Quote
  #5 (permalink)  
Old 07-10-09, 13:53
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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.
Reply With Quote
  #6 (permalink)  
Old 07-10-09, 15:32
swati malla swati malla is offline
Registered User
 
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.....
Reply With Quote
  #7 (permalink)  
Old 07-11-09, 03:10
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
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
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
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