Use java interface "setArray" to insert the array of user-defined type to table

Поиск
Список
Период
Сортировка
От Charles Kong
Тема Use java interface "setArray" to insert the array of user-defined type to table
Дата
Msg-id CA+PCg_ymO5pJ=zK+m6NGdwTNkZ5gtMQJ+_hNUuaQiwRkCPDhTA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Use java interface "setArray" to insert the array of user-defined type to table
Can 32bit libpq to access 64bit postgres
Can 64bit libpq to access 32bit postgres
Список pgsql-interfaces
Hi all,
I use a user-defined type in “schema.sql”
CREATE TYPE infoEntity AS (
    "entity_id" bigint,
    "seq" integer,
    "message" varchar(255)
)

in java code:
java_infoEntity[] infoEntityArray; //java_infoEntity is the class with the same member variables.
infoEntityArray = new java_infoEntity[3];
infoEntityArray[0] = new java_infoEntity();
....

//info_Entity's type is user-defined type "infoEntity". 
sql = "insert into \"T_abc\" (info_Entity) values(?);";
statement = conn.prepareStatement( sql );
Array array = conn.createArrayOf("infoEntity",  infoEntityArray);
statement.setArray(1,array);
statement.addBatch();
statement.executeBatch();
....
....
Sql throw exception: 
sqlException:  SQLState: 22P02 Error Code: 0 Error Message: Batch entry 0 insert into "T_abc" (info_Entity) values('{"com.xxx.java_infoEntity@597d57aa"}') was aborted: ERROR: malformed record literal: "com.xxx.java_infoEntity@597d57aa"

How to cope with it?

В списке pgsql-interfaces по дате отправления:

Предыдущее
От: trn nrjn
Дата:
Сообщение: PREPARE TRANSACTION for specific transaction branch/session
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Use java interface "setArray" to insert the array of user-defined type to table