pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Assad Jarrahian <jarraa@gmail.com>
To: pgsql-general@postgresql.org
To: pgsql-jdbc@postgresql.org
Subject: SQLData user-defined-types and getObject()
Date: Sat, 7 Jan 2006 20:28:28 -0700
Message-ID: <4bd3e1480601071928r372ccb5ct8653d50558edeba@mail.gmail.com> (raw)

Hi All,
  I am quite confused (PLEASE PLEASE Help), I cannot find anything on
the web). I read that you can declare a class that implements SQLData
(in this case I set up a class called Complex from the /src/tutorial
datatype that mimics the user-defined datatype in the db) and then set
the mapping appropriately (see below).
   But it does not work ( I maybe doing something wrong)!!!
The "getObject" code throws:
Exception in thread "main" org.postgresql.util.PSQLException:
Unsupported Types value: 2,000
and the setObject code throws:
Exception in thread "main" java.lang.ClassCastException: java.lang.Class
 (points to the getObject() line

ANY help would be much appreciated!
much thanks in advance.
-assad

Reference:
//Mapping type setup
		java.util.Map map = db.getTypeMap();
		if(map == null) map = new HashMap();
		map.put("complex", Class.forName("Complex"));
		db.setTypeMap(map);
		
		map = db.getTypeMap();

and then I can set and get as follows:

//set info
		Complex test = new Complex();
		test.a = 5.6;
		test.b = 3.4;
		Statement stmt = db.createStatement();
		PreparedStatement temp = db.prepareStatement("INSERT INTO
test_complex VALUES (DEFAULT, ?);");
		temp.setObject(1,test);
	temp.executeUpdate();

//I also  tried with setObject with the type specified to
java.sql.TYPE_JavaObject

//get info

	ResultSet rs = stmt.executeQuery("SELECT * FROM test_complex");
		System.out.println("Got ");
		
		while(rs.next()){
			System.out.println("Got ");
		ResultSetMetaData metaData = rs.getMetaData();
		System.out.println("Type from SQL: " +
		metaData.getColumnTypeName(2));

		Object foo = (Object) rs.getObject(2, map);

		if (foo instanceof Complex) {
		Complex cp = (Complex)foo;
		System.out.println("Got: " + cp + " from DB");



view thread (2+ messages)  latest in thread

Message-ID: <4bd3e1480601071928r372ccb5ct8653d50558edeba@mail.gmail.com>
Permalink:  ../4bd3e1480601071928r372ccb5ct8653d50558edeba@mail.gmail.com/
Also on:    postgresql.org/message-id/4bd3e1480601071928r372ccb5ct8653d50558edeba@mail.gmail.com

 · 

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: jarraa@gmail.com, pgsql-general@postgresql.org
  Subject: Re: SQLData user-defined-types and getObject()
  In-Reply-To: <4bd3e1480601071928r372ccb5ct8653d50558edeba@mail.gmail.com>
  References: <4bd3e1480601071928r372ccb5ct8653d50558edeba@mail.gmail.com>

* 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