我正在将 postgres9.4 EDB 用于带有 UDT(用户定义类型)的函数,给出 Is Not Yet Implemented 异常。我正在为 JDBC 使用 postgres 驱动程序 postgresql-9.4-1203.jdbc41.jar。上面的jar是否支持UDT功能?这个实现是部分的吗?
请帮我。
下面是代码,
public static void oracleToPosgresUDTCall() {
System.out.println("@@@ inside oracleToPosgresUDTCall...");
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5433/pgtest", "postgres", "root");
System.out.println(c.getMetaData().getDriverVersion());
//you can mad your UDT to pojo here Great !!!
Map<String, Class<?>> m = c.getTypeMap();
m.put("typ_address", Address.class);
m.put("typ_test", AddressTypeTest.class);
c.setTypeMap(m);
// Procedure call
CallableStatement cstmt = c.prepareCall("{call fn_test_t(?,?,?)}");
cstmt.setString(1, "791000252423");
cstmt.registerOutParameter(2, Types.ARRAY);
cstmt.registerOutParameter(3, Types.ARRAY);
boolean b = cstmt.execute();
Array arr = cstmt.getArray(1); //output array starts from index 1
System.out.println("arr:" + arr.getBaseTypeName());
Object obj = arr.getArray();
System.out.println("Address obj:" + obj);
Address[] a = (Address[])obj;
System.out.println("Address obj:" + a[0].getAdd1());
System.out.println("Address obj:" + a[0].getTypeTest().getT1());
System.out.println("=======================================================");
//MORE
List<Address> list = Arrays.asList(a);
for(Address aa: list){
System.out.println(aa.getAdd1());
System.out.println(aa.getAdd2());
System.out.println("t1:" + aa.getTypeTest().getT1());
}
cstmt.close();
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}