From: Chris Smith <cdsmith@twu.net>
To: aparna <aparna@chintech.org>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: postgres-jdbc
Date: Thu, 17 Mar 2005 06:56:13 -0700
Message-ID: <010b01c52af9$153279e0$7500000a@KALIO> (raw)
References: <423988C2.6090407@chintech.org>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: cdsmith@twu.net, aparna@chintech.org
Subject: Re: postgres-jdbc
In-Reply-To: <010b01c52af9$153279e0$7500000a@KALIO>
References: <423988C2.6090407@chintech.org> <010b01c52af9$153279e0$7500000a@KALIO>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox