X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F32039DCAA1 for ; Sat, 7 Jan 2006 23:28:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34948-07 for ; Sat, 7 Jan 2006 23:28:30 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.194]) by postgresql.org (Postfix) with ESMTP id B733D9DC8A7 for ; Sat, 7 Jan 2006 23:28:23 -0400 (AST) Received: by wproxy.gmail.com with SMTP id 57so3090960wri for ; Sat, 07 Jan 2006 19:28:28 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=okTwQbZecZnQjQeV8ogy47qMPrIVhdNR5WSoyF0zbRqx7JX2F5uafN+6mgmg64ygZuD5DjJY3lD0Y54iO/XdAL4mtZ332xz1Npk3zY0z9QZM4nEf5gGclHzSsKCfjdXEnn8O6av+k/cqPeOwxqAmUdG/eTf9e2u1qJsJmxPbrzA= Received: by 10.65.119.10 with SMTP id w10mr2253830qbm; Sat, 07 Jan 2006 19:28:28 -0800 (PST) Received: by 10.65.95.1 with HTTP; Sat, 7 Jan 2006 19:28:28 -0800 (PST) Message-ID: <4bd3e1480601071928r372ccb5ct8653d50558edeba@mail.gmail.com> Date: Sat, 7 Jan 2006 20:28:28 -0700 From: Assad Jarrahian To: pgsql-general@postgresql.org, pgsql-jdbc@postgresql.org Subject: SQLData user-defined-types and getObject() MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.105 required=5 tests=[AWL=0.105] X-Spam-Score: 0.105 X-Spam-Level: X-Archive-Number: 200601/363 X-Sequence-Number: 89308 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 =09=09java.util.Map map =3D db.getTypeMap(); =09=09if(map =3D=3D null) map =3D new HashMap(); =09=09map.put("complex", Class.forName("Complex")); =09=09db.setTypeMap(map); =09=09 =09=09map =3D db.getTypeMap(); and then I can set and get as follows: //set info =09=09Complex test =3D new Complex(); =09=09test.a =3D 5.6; =09=09test.b =3D 3.4; =09=09Statement stmt =3D db.createStatement(); =09=09PreparedStatement temp =3D db.prepareStatement("INSERT INTO test_complex VALUES (DEFAULT, ?);"); =09=09temp.setObject(1,test); =09temp.executeUpdate(); //I also tried with setObject with the type specified to java.sql.TYPE_JavaObject //get info =09ResultSet rs =3D stmt.executeQuery("SELECT * FROM test_complex"); =09=09System.out.println("Got "); =09=09 =09=09while(rs.next()){ =09=09=09System.out.println("Got "); =09=09ResultSetMetaData metaData =3D rs.getMetaData(); =09=09System.out.println("Type from SQL: " + =09=09metaData.getColumnTypeName(2)); =09=09Object foo =3D (Object) rs.getObject(2, map); =09=09if (foo instanceof Complex) { =09=09Complex cp =3D (Complex)foo; =09=09System.out.println("Got: " + cp + " from DB");