X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B60D8565DB for ; Thu, 17 Mar 2005 13:56:23 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39434-07 for ; Thu, 17 Mar 2005 13:56:13 +0000 (GMT) Received: from andrea.pop4.net (www.pop4.net [216.234.109.11]) by svr1.postgresql.org (Postfix) with SMTP id 110135656A for ; Thu, 17 Mar 2005 13:56:12 +0000 (GMT) Received: (qmail 45855 invoked by uid 1008); 17 Mar 2005 13:56:12 -0000 Received: from cdsmith@twu.net by www.pop4.net with qmail-scanner-0.96 (uvscan: v4.1.40/v4156. . Clean. Processed in 0.687397 secs); 17 Mar 2005 13:56:12 -0000 Received: from unknown (HELO KALIO) (69.171.228.185) by 0 with SMTP; 17 Mar 2005 13:56:11 -0000 Message-ID: <010b01c52af9$153279e0$7500000a@KALIO> From: "Chris Smith" To: "aparna" Cc: References: <423988C2.6090407@chintech.org> Subject: Re: postgres-jdbc Date: Thu, 17 Mar 2005 06:56:13 -0700 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/160 X-Sequence-Number: 12552 aparna wrote: > i'm doing it in Java. > Is there any way to retrieve the structure of a table from the java > program and display it? > > I tried to execute the command \d using the program. > it worked. > But i couldn't get the result. \d is a meta-command in psql, and it only works in psql. The same basic information, though, is available through JDBC. Take a look at the java.sql.DatabaseMetaData class in your copy of the Java API documentation. Basically, once you've opened a connection of the database, call getMetaData on the connection, and then call methods of the resulting class. The columns in a table are available by calling getColumns(...) on DatabaseMetaData. The results are (confusingly) returned in a ResultSet instead of a more specific data structure, so you'll need to make frequent reference to the API documentation in order to interpret what you get back. Also, since the structure of that ResultSet is specified by Java and not by PostgreSQL, there will be many inapplicable or undeterminable columns. However, it will give you the same information provided about table columns by "\d" in psql. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation