Re: postgres-jdbc

Поиск
Список
Период
Сортировка
От Chris Smith
Тема Re: postgres-jdbc
Дата
Msg-id 010b01c52af9$153279e0$7500000a@KALIO
обсуждение исходный текст
Ответ на postgres-jdbc  (aparna <aparna@chintech.org>)
Список 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


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "mikael-aronsson"
Дата:
Сообщение: Re: postgres-jdbc
Следующее
От: Roland Walter
Дата:
Сообщение: Re: postgres-jdbc