jdbc / user data type (written in C)

From: gfaruch(at)laposte(dot)net (=?ISO-8859-1?Q?Gr=E9gory_Faruch?=)
To: pgsql-general(at)postgresql(dot)org
Subject: jdbc / user data type (written in C)
Date: 2003-05-12 19:54:05
Message-ID: 2896c729.0305121154.264dcbb7@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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();

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Ayers 2003-05-12 20:04:57 Re: VARCHAR performance issue
Previous Message Nigel J. Andrews 2003-05-12 19:43:06 Re: PREPARED ...