jdbc / user data type (written in C) - Mailing list pgsql-general

From gfaruch@laposte.net (Grégory Faruch)
Subject jdbc / user data type (written in C)
Date
Msg-id 2896c729.0305121154.264dcbb7@posting.google.com
Whole thread Raw
List pgsql-general
hello,

I'am trying to retrieve a user data of type 'complex' (the one defined
in the
postgresql src tree : src/tutorial) fron a java class.
But i have this exception :

Exception in thread "main" java.lang.ClassCastException:
java.lang.Class
        at org.postgresql.jdbc2.AbstractJdbc2Connection.getObject(AbstractJdbc2Connection.java:125)
        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getObject(AbstractJdbc2ResultSet.java:147)
        at testtmp.main(testtmp.java:64)
I'll appreciate some help or any pointers ... thanks all.

gregory

my short code :

class Complex implements SQLData
{
  public double a;
  public double b;

  private String sql_type;

  public String getSQLTypeName() {
    return sql_type;
  }

  public void readSQL(SQLInput stream, String type)
    throws SQLException {
    sql_type = type;
    a = stream.readDouble();
    b = stream.readDouble();
  }

  public void writeSQL(SQLOutput stream)
    throws SQLException {
    stream.writeDouble(a);
    stream.writeDouble(b);
  }
}

        java.util.Map map = db.getTypeMap();
        if(map == null) map = new HashMap();
        map.put("complex", Class.forName("Complex"));
        db.setTypeMap(map);

        map = db.getTypeMap();

        Statement stmt = db.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM test_complex");

        while(rs.next()){
        ResultSetMetaData metaData = rs.getMetaData();
        System.out.println("Type from SQL: " +
metaData.getColumnTypeName(1));

        Object foo = rs.getObject(1);

        if (foo instanceof Complex) {
            Complex cp = (Complex)foo;
            System.out.println("Got: " + cp + " from DB");
        }
        else {
            System.out.println("Class name: " + foo.getClass().getName());
            System.out.println("Got " + foo);
        }
        }
        stmt.close();
        db.close();


pgsql-general by date:

Previous
From: Michelle Konzack
Date:
Subject: How to run more the one database at once ?
Next
From: pawlicki@mailandnews.com (John Pawlicki)
Date:
Subject: Problem Starting Postgresql after upgrade from SuSE8.1 to SuSE 8.2