Re: postgres-jdbc

From: "Chris Smith" <cdsmith(at)twu(dot)net>
To: "aparna" <aparna(at)chintech(dot)org>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: postgres-jdbc
Date: 2005-03-17 13:56:13
Message-ID: 010b01c52af9$153279e0$7500000a@KALIO
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Javier Yáñez 2005-03-17 15:47:04 Re: Charset encoding patch to JDBC driver
Previous Message Roland Walter 2005-03-17 13:56:10 Re: postgres-jdbc