pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Marcin Gala <mailing@siec.mine.nu>
Cc: Postgres jdbc mailing list <pgsql-jdbc@postgresql.org>
Subject: Re: JDBC and composite types
Date: Mon, 21 May 2007 11:35:11 -0400 (EDT)
Message-ID: <Pine.BSO.4.64.0705211122380.2299@leary.csoft.net> (raw)
In-Reply-To: <464EDE37.8060201@siec.mine.nu>
References: <464EDE37.8060201@siec.mine.nu>



On Sat, 19 May 2007, Marcin Gala wrote:

> Could anyone tell me, how to read table's columns that are of composite type? 
> I was trying to use getObject with different types of casting, however 
> nothing worked

Technically getObject on a complex type should return an instance of 
java.sql.Struct by default or an instance of java.sql.SQLData if the type 
has been mapped to a specific java class.  This has not been implemented 
in the pg driver yet though.

> :( Also getString doesn't give me a string representation of type...
>

It does for me.  See the attached example.

Kris Jurka

Attachments:

CompositeType.java (text/plain, 766B) download import java.sql.*; public class CompositeType { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5830/jurka","jurka",""); Statement stmt = conn.createStatement(); try { stmt.execute("DROP TABLE comptable"); stmt.execute("DROP TYPE mycomplex"); } catch (SQLException sqle) {} stmt.execute("CREATE TYPE mycomplex AS (a int, b int) "); stmt.execute("CREATE TABLE comptable (id int, val mycomplex)"); stmt.execute("INSERT INTO comptable VALUES (1, ROW(2,3))"); ResultSet rs = stmt.executeQuery("SELECT id, val FROM comptable"); rs.next(); System.out.println(rs.getString(2)); } }

view thread (2+ messages)

Message-ID: <Pine.BSO.4.64.0705211122380.2299@leary.csoft.net>
Permalink:  ../Pine.BSO.4.64.0705211122380.2299@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.64.0705211122380.2299@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, mailing@siec.mine.nu
  Subject: Re: JDBC and composite types
  In-Reply-To: <Pine.BSO.4.64.0705211122380.2299@leary.csoft.net>
  References: <464EDE37.8060201@siec.mine.nu> <Pine.BSO.4.64.0705211122380.2299@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