From: | Sridhar N Bamandlapally <sridhar(dot)bn1(at)gmail(dot)com> |
---|---|
To: | Andreas Joseph Krogh <andreas(at)visena(dot)com> |
Cc: | List <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: JDBC behaviour |
Date: | 2016-02-18 09:42:37 |
Message-ID: | CAGuFTBUm6833idGepWE9KBP87nYBuzHpTqwmf0981wCdS13K0w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers pgsql-jdbc |
yes John,
but why?, this is not expected behavior
autocommit is just autocommit, its not responsible to treat
multi-transactions as single or independent
On Thu, Feb 18, 2016 at 3:08 PM, Sridhar N Bamandlapally <
sridhar(dot)bn1(at)gmail(dot)com> wrote:
> let me put this way
>
> table employee ( id PrimaryKey, name )
>
> In Java ( just little pseudo-code way )
>
> try {
> conn.setAutoCommit(false);
> try { executeUpdate("insert into employee(id,name) values(1, 'K1')");
> } catch ...
> try { executeUpdate("insert into employee(id,name) values(1, 'K1')");
> } catch ...
> try { executeUpdate("insert into employee(id,name) values(1, 'K2')");
> } catch ...
> conn.commit();
> } catch ...
>
> throws error
> 1. duplicate key value violates unique constraint "employee_pkey"
> 2. current transaction is aborted, commands ignored until end of
> transaction block
>
>
> In PL/SQL ( similar error thrown when used BEGIN-END )
>
> postgres=# begin;
> BEGIN
> postgres=# insert into employee values (1,'aa');
> INSERT 0 1
> postgres=# insert into employee values (2,'bb');
> INSERT 0 1
> postgres=# insert into employee values (3,'cc');
> INSERT 0 1
> postgres=# insert into employee values (1,'aa');
> ERROR: duplicate key value violates unique constraint "employee_pkey"
> DETAIL: Key (eid)=(1) already exists.
> postgres=# insert into employee values (4,'dd');
> ERROR: current transaction is aborted, commands ignored until end of
> transaction block
>
>
> my question Java setAutoCommit (false) is behaving like PL/SQL BEGIN-END
>
>
>
>
> On Thu, Feb 18, 2016 at 2:54 PM, Andreas Joseph Krogh <andreas(at)visena(dot)com>
> wrote:
>
>> På torsdag 18. februar 2016 kl. 10:20:51, skrev Sridhar N Bamandlapally <
>> sridhar(dot)bn1(at)gmail(dot)com>:
>>
>> setAutoCommit(false), it should not be treating all next transactions as
>> single set, simple, this is what expected behavior
>>
>>
>> The point is that all subsequent statements (after an exception) are part
>> of *the same* transaction (in autocommit=false mode). So you have to
>> issue an explicit ROLLBACK before any new statement can give meaningful
>> results.
>>
>> --
>> *Andreas Joseph Krogh*
>> CTO / Partner - Visena AS
>> Mobile: +47 909 56 963
>> andreas(at)visena(dot)com
>> www.visena.com
>> <https://www.visena.com>
>>
>>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Joseph Krogh | 2016-02-18 09:46:12 | Re: JDBC behaviour |
Previous Message | Sridhar N Bamandlapally | 2016-02-18 09:38:23 | Re: JDBC behaviour |
From | Date | Subject | |
---|---|---|---|
Next Message | Etsuro Fujita | 2016-02-18 09:45:47 | Re: Optimization for updating foreign tables in Postgres FDW |
Previous Message | Sridhar N Bamandlapally | 2016-02-18 09:38:23 | Re: JDBC behaviour |
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Joseph Krogh | 2016-02-18 09:46:12 | Re: JDBC behaviour |
Previous Message | Sridhar N Bamandlapally | 2016-02-18 09:38:23 | Re: JDBC behaviour |