pg.ddx.io pgsql-jdbc@postgresql.org mailing list archivehelp / color / mirror / Atom feed
JDBC and composite types 2+ messages / 2 participants [nested] [flat]
* JDBC and composite types @ 2007-05-19 11:23 Marcin Gala <mailing@siec.mine.nu> 2007-05-21 15:35 ` Re: JDBC and composite types Kris Jurka <books@ejurka.com> 0 siblings, 1 reply; 2+ messages in thread From: Marcin Gala @ 2007-05-19 11:23 UTC (permalink / raw) To: pgsql-jdbc 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 :( Also getString doesn't give me a string representation of type... My type is: CREATE TYPE forwarding_number AS (always number_type, busy number_type, "notResponding" number_type, "notLogged" number_type); I'm trying to get data from table X where column y is of type forwarding_number. Marcin ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: JDBC and composite types 2007-05-19 11:23 JDBC and composite types Marcin Gala <mailing@siec.mine.nu> @ 2007-05-21 15:35 ` Kris Jurka <books@ejurka.com> 0 siblings, 0 replies; 2+ messages in thread From: Kris Jurka @ 2007-05-21 15:35 UTC (permalink / raw) To: Marcin Gala <mailing@siec.mine.nu>; +Cc: pgsql-jdbc 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:^ permalink raw reply [nested|flat] 2+ messages in threadCompositeType.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)); } }
end of thread, other threads:[~2007-05-21 15:35 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2007-05-19 11:23 JDBC and composite types Marcin Gala <mailing@siec.mine.nu> 2007-05-21 15:35 ` Kris Jurka <books@ejurka.com>
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