pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Gaƫl BOUGANNE <gael.bouganne@univ-nantes.fr>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Getting views' metadata
Date: Wed, 10 Jun 2009 18:53:20 -0400 (EDT)
Message-ID: <alpine.BSO.2.00.0906101852170.24632@leary.csoft.net> (raw)
In-Reply-To: <4A2E4D3C.6040908@univ-nantes.fr>
References: <4A2E4D3C.6040908@univ-nantes.fr>



On Tue, 9 Jun 2009, Ga?l BOUGANNE wrote:

> i'm trying to retrieve complete metadata of my pgsql 8.3 database using 
> JDBC. But i got a problem getting the columns informations of views. I 
> succesfully get the view names using 'getTables(...)' method, but when 
> calling 'getColumns(...)' for a given view, the returned ResultSet is 
> empty.

It certainly works for me (as attached).  If you can produce a similar 
counterexample which doesn't work, I'll certainly try and figure out 
what's wrong.

Kris Jurka

Attachments:

ViewMD.java (text/plain, 1.1K) download import java.sql.*; public class ViewMD { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5844/jurka","jurka",""); Statement stmt = conn.createStatement(); stmt.execute("CREATE TEMP TABLE mytemptable (a int, b text)"); stmt.execute("CREATE TEMP VIEW mytempview AS SELECT a, b, 3 as c FROM mytemptable"); stmt.close(); DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getColumns("%", "%", "mytempview", "%"); printResultSet(rs); conn.close(); } public static void printResultSet(ResultSet rs) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { if (i != 1) { System.out.print(", "); } System.out.print(rsmd.getColumnName(i)); } System.out.println(); while (rs.next()) { for (int i = 1; i <= rsmd.getColumnCount(); i++) { if (i != 1) { System.out.print(", "); } System.out.print(rs.getString(i)); } System.out.println(); } } }

view thread (2+ messages)

Message-ID: <alpine.BSO.2.00.0906101852170.24632@leary.csoft.net>
Permalink:  ../alpine.BSO.2.00.0906101852170.24632@leary.csoft.net/
Also on:    postgresql.org/message-id/alpine.BSO.2.00.0906101852170.24632@leary.csoft.net

 · 

reply

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: books@ejurka.com, gael.bouganne@univ-nantes.fr
  Subject: Re: Getting views' metadata
  In-Reply-To: <alpine.BSO.2.00.0906101852170.24632@leary.csoft.net>
  References: <4A2E4D3C.6040908@univ-nantes.fr> <alpine.BSO.2.00.0906101852170.24632@leary.csoft.net>

* 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