public inbox for [email protected]  
help / color / mirror / Atom feed
Use java interface "setArray" to insert the array of user-defined type to table
2+ messages / 2 participants
[nested] [flat]

* Use java interface "setArray" to insert the array of user-defined type to table
@ 2022-02-23 14:58 Charles Kong <[email protected]>
  2022-02-23 15:00 ` Re: Use java interface "setArray" to insert the array of user-defined type to table Dave Cramer <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Charles Kong @ 2022-02-23 14:58 UTC (permalink / raw)
  To: [email protected]

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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Use java interface "setArray" to insert the array of user-defined type to table
  2022-02-23 14:58 Use java interface "setArray" to insert the array of user-defined type to table Charles Kong <[email protected]>
@ 2022-02-23 15:00 ` Dave Cramer <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Cramer @ 2022-02-23 15:00 UTC (permalink / raw)
  To: Charles Kong <[email protected]>; +Cc: [email protected]

On Wed, 23 Feb 2022 at 09:58, Charles Kong <[email protected]> wrote:

> 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?*
>
>
The JDBC driver does not know how to deal with user defined types. You will
have to write code to serialize the type yourself.

Regards,
Dave


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2022-02-23 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 14:58 Use java interface "setArray" to insert the array of user-defined type to table Charles Kong <[email protected]>
2022-02-23 15:00 ` Dave Cramer <[email protected]>

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