Re: JDBC behaviour

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: JDBC behaviour
Date: 2016-02-21 07:39:48
Message-ID: nabpk4$4sc$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-jdbc

Sridhar N Bamandlapally schrieb am 21.02.2016 um 03:20:
> Hi
>
> My expectation is simple, please refer below
>
> create table employee(empid numeric(4) primary key, ename varchar(20));
>
> from Java/jdbc code, conn.setAutoCommit(false)
>
> insert into employee values(1, 'K1');
> insert into employee values(1, 'K1');
> insert into employee values(2, 'K2');
>
> by looking at exceptions i may rollback or commit, i.e. conn.rollback() or conn.commit()
> if I rollback table should be empty,
> if I commit table should have 2 rows
>
> is there any way is possible ?

Use on conflict do nothing:

insert into employee values(1, 'K1') on conflict (empid) do nothing;
insert into employee values(1, 'K1') on conflict (empid) do nothing;
insert into employee values(2, 'K2') on conflict (empid) do nothing;

This can be combined with a PreparedStatement and batching if needed.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2016-02-21 09:03:22 Re: BRIN Usage
Previous Message Vitalii Tymchyshyn 2016-02-21 04:40:20 Re: JDBC behaviour

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2016-02-21 08:01:29 Re: checkpointer continuous flushing - V18
Previous Message Fabien COELHO 2016-02-21 07:26:28 Re: checkpointer continuous flushing - V18

Browse pgsql-jdbc by date

  From Date Subject
Next Message Bill Moran 2016-02-21 12:56:09 Re: JDBC behaviour
Previous Message Vitalii Tymchyshyn 2016-02-21 04:40:20 Re: JDBC behaviour