public inbox for [email protected]  
help / color / mirror / Atom feed
From: Charles Kong <[email protected]>
To: [email protected]
Subject: Use java interface "setArray" to insert the array of user-defined type to table
Date: Wed, 23 Feb 2022 14:58:04 +0000
Message-ID: <CA+PCg_ymO5pJ=zK+m6NGdwTNkZ5gtMQJ+_hNUuaQiwRkCPDhTA@mail.gmail.com> (raw)

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?*


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Use java interface "setArray" to insert the array of user-defined type to table
  In-Reply-To: <CA+PCg_ymO5pJ=zK+m6NGdwTNkZ5gtMQJ+_hNUuaQiwRkCPDhTA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox