pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedhow to continue using a connection after an error with autocommit=false
7+ messages / 6 participants
[nested] [flat]
* how to continue using a connection after an error with autocommit=false
@ 2007-02-20 10:41 James Im <im-james@hotmail.com>
2007-02-20 10:50 ` Re: how to continue using a connection after an error with autocommit=false Heikki Linnakangas <heikki@enterprisedb.com>
2007-02-20 10:53 ` Re: how to continue using a connection after an error with autocommit=false Altaf Malik <mmalik_altaf@yahoo.com>
0 siblings, 2 replies; 7+ messages in thread
From: James Im @ 2007-02-20 10:41 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
I just find out that I cannot continue using a connection when I use
autocommit=false and that an sql insert failed.
In pseudo code this is what I'd like to do:
1) create connection
2) set autocommit = false
3) do an insert that succeed
4) do an insert that fails
5) catch the SQLException (I don't do a rollback on purpose)
6) do a select with the same connection
7) do another insert
8) commit
Everything goes well until step (6). where I receive the following error:
ERROR: current transaction is aborted, commands ignored until end of
transaction block
Exception: org.postgresql.util.PSQLException
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:258)
Can I do something is step (5) so that I don't get the error in step (6) ?
I need to continue using the same connection.
Thanks you your help.
_________________________________________________________________
Vælg selv hvordan du vil kommunikere - skrift, tale, video eller billeder
med MSN Messenger: http://messenger.msn.dk/ - her kan du det hele
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: how to continue using a connection after an error with autocommit=false
2007-02-20 10:41 how to continue using a connection after an error with autocommit=false James Im <im-james@hotmail.com>
@ 2007-02-20 10:50 ` Heikki Linnakangas <heikki@enterprisedb.com>
2007-02-28 20:41 ` Re: how to continue using a connection after an error with autocommit=false Tim Pizey <timp@melati.org>
1 sibling, 1 reply; 7+ messages in thread
From: Heikki Linnakangas @ 2007-02-20 10:50 UTC (permalink / raw)
To: James Im <im-james@hotmail.com>; +Cc: pgsql-jdbc
James Im wrote:
> I just find out that I cannot continue using a connection when I use
> autocommit=false and that an sql insert failed.
That's intended behavior in PostgreSQL. I just wrote this in another
thread last week:
If you have a statement in your transaction that you know might fail,
you can use savepoints to avoid having to restart the whole transaction:
Savepoint sp = conn.setSavepoint();
try {
stmt.executeQuery("SELECT 1 FROM table_that_might_not_exist");
} catch(SQLException ex)
{
sp.rollback(sp);
}
stmt.executeQuery("SELECT * FROM table_that_exists");
...
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: how to continue using a connection after an error with autocommit=false
2007-02-20 10:41 how to continue using a connection after an error with autocommit=false James Im <im-james@hotmail.com>
2007-02-20 10:50 ` Re: how to continue using a connection after an error with autocommit=false Heikki Linnakangas <heikki@enterprisedb.com>
@ 2007-02-28 20:41 ` Tim Pizey <timp@melati.org>
2007-02-28 22:33 ` Re: how to continue using a connection after an error with autocommit=false Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 7+ messages in thread
From: Tim Pizey @ 2007-02-28 20:41 UTC (permalink / raw)
To: pgsql-jdbc
On Tuesday 20 February 2007 10:50, Heikki Linnakangas wrote:
> James Im wrote:
> > I just find out that I cannot continue using a connection when I use
> > autocommit=false and that an sql insert failed.
>
> That's intended behavior in PostgreSQL.
[snip]
This is new behaviour in version 8, I believe.
I think this behaviour is unique to Postgresql?
Melati was developed with Postgresql version 6 as the target dbms
back in 2000, since then it has been extended to work with the other common
dbmsen, but now it looks like it won't work with V8, without quite a bit of
rework.
Is this behaviour specified by a standard?
What are the advantages?
yours
Tim Pizey
--
http://melati.org/ - the flower of Java.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: how to continue using a connection after an error with autocommit=false
2007-02-20 10:41 how to continue using a connection after an error with autocommit=false James Im <im-james@hotmail.com>
2007-02-20 10:50 ` Re: how to continue using a connection after an error with autocommit=false Heikki Linnakangas <heikki@enterprisedb.com>
2007-02-28 20:41 ` Re: how to continue using a connection after an error with autocommit=false Tim Pizey <timp@melati.org>
@ 2007-02-28 22:33 ` Dave Cramer <pg@fastcrypt.com>
2007-03-01 20:59 ` Re: how to continue using a connection after an error with autocommit=false Tim Pizey <timp@melati.org>
0 siblings, 1 reply; 7+ messages in thread
From: Dave Cramer @ 2007-02-28 22:33 UTC (permalink / raw)
To: Tim Pizey <timp@melati.org>; +Cc: pgsql-jdbc
On 28-Feb-07, at 3:41 PM, Tim Pizey wrote:
> On Tuesday 20 February 2007 10:50, Heikki Linnakangas wrote:
>> James Im wrote:
>>> I just find out that I cannot continue using a connection when I use
>>> autocommit=false and that an sql insert failed.
>>
>> That's intended behavior in PostgreSQL.
> [snip]
> This is new behaviour in version 8, I believe.
>
No, this has been around since 7.x
> I think this behaviour is unique to Postgresql?
>
Possibly
> Melati was developed with Postgresql version 6 as the target dbms
> back in 2000, since then it has been extended to work with the
> other common
> dbmsen, but now it looks like it won't work with V8, without quite
> a bit of
> rework.
>
> Is this behaviour specified by a standard?
>
> What are the advantages?
>
The advantage is that a transaction is atomic.
You can continue to use the connection, you simply have to rollback
the transaction after the error and start over.
You can also use savepoints.
> yours
> Tim Pizey
>
> --
> http://melati.org/ - the flower of Java.
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that
> your
> message can get through to the mailing list cleanly
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: how to continue using a connection after an error with autocommit=false
2007-02-20 10:41 how to continue using a connection after an error with autocommit=false James Im <im-james@hotmail.com>
2007-02-20 10:50 ` Re: how to continue using a connection after an error with autocommit=false Heikki Linnakangas <heikki@enterprisedb.com>
2007-02-28 20:41 ` Re: how to continue using a connection after an error with autocommit=false Tim Pizey <timp@melati.org>
2007-02-28 22:33 ` Re: how to continue using a connection after an error with autocommit=false Dave Cramer <pg@fastcrypt.com>
@ 2007-03-01 20:59 ` Tim Pizey <timp@melati.org>
0 siblings, 0 replies; 7+ messages in thread
From: Tim Pizey @ 2007-03-01 20:59 UTC (permalink / raw)
To: pgsql-jdbc
On Wednesday 28 February 2007 22:33, Dave Cramer wrote:
> On 28-Feb-07, at 3:41 PM, Tim Pizey wrote:
> > On Tuesday 20 February 2007 10:50, Heikki Linnakangas wrote:
> >> James Im wrote:
> >>> I just find out that I cannot continue using a connection when I use
> >>> autocommit=false and that an sql insert failed.
> >>
> >> That's intended behavior in PostgreSQL.
> >
> > [snip]
> > This is new behaviour in version 8, I believe.
>
> No, this has been around since 7.x
>
> > I think this behaviour is unique to Postgresql?
>
> Possibly
>
> > Melati was developed with Postgresql version 6 as the target dbms
> > back in 2000, since then it has been extended to work with the
> > other common
> > dbmsen, but now it looks like it won't work with V8, without quite
> > a bit of
> > rework.
> >
Sorry, my bad, all Melati's tests pass on 8.1.4, without modification.
yours
Tim Pizey
--
http://melati.org/ - the flower of Java.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: how to continue using a connection after an error with autocommit=false
2007-02-20 10:41 how to continue using a connection after an error with autocommit=false James Im <im-james@hotmail.com>
@ 2007-02-20 10:53 ` Altaf Malik <mmalik_altaf@yahoo.com>
2007-02-20 15:39 ` Re: how to continue using a connection after an error with autocommit=false Scott Marlowe <smarlowe@g2switchworks.com>
1 sibling, 1 reply; 7+ messages in thread
From: Altaf Malik @ 2007-02-20 10:53 UTC (permalink / raw)
To: James Im <im-james@hotmail.com>; pgsql-jdbc
You can either commit or rollback the transaction when you encounter an SQL error. This will alow the next statements to execute successfully.
--Altaf Malik
EnterpriseDB
www.enterprisedb.com
James Im <im-james@hotmail.com> wrote:
Hi,
I just find out that I cannot continue using a connection when I use
autocommit=false and that an sql insert failed.
In pseudo code this is what I'd like to do:
1) create connection
2) set autocommit = false
3) do an insert that succeed
4) do an insert that fails
5) catch the SQLException (I don't do a rollback on purpose)
6) do a select with the same connection
7) do another insert
8) commit
Everything goes well until step (6). where I receive the following error:
ERROR: current transaction is aborted, commands ignored until end of
transaction block
Exception: org.postgresql.util.PSQLException
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:258)
Can I do something is step (5) so that I don't get the error in step (6) ?
I need to continue using the same connection.
Thanks you your help.
_________________________________________________________________
Vælg selv hvordan du vil kommunikere - skrift, tale, video eller billeder
med MSN Messenger: http://messenger.msn.dk/ - her kan du det hele
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
---------------------------------
Don't get soaked. Take a quick peak at the forecast
with theYahoo! Search weather shortcut.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: how to continue using a connection after an error with autocommit=false
2007-02-20 10:41 how to continue using a connection after an error with autocommit=false James Im <im-james@hotmail.com>
2007-02-20 10:53 ` Re: how to continue using a connection after an error with autocommit=false Altaf Malik <mmalik_altaf@yahoo.com>
@ 2007-02-20 15:39 ` Scott Marlowe <smarlowe@g2switchworks.com>
0 siblings, 0 replies; 7+ messages in thread
From: Scott Marlowe @ 2007-02-20 15:39 UTC (permalink / raw)
To: Altaf Malik <mmalik_altaf@yahoo.com>; +Cc: James Im <im-james@hotmail.com>; pgsql-jdbc
On Tue, 2007-02-20 at 04:53, Altaf Malik wrote:
> You can either commit or rollback the transaction when you encounter
> an SQL error. This will alow the next statements to execute
> successfully.
You can't commit after an error in PostgreSQL unless you've rolled back
to a savepoint from before the error.
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2007-03-01 20:59 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-02-20 10:41 how to continue using a connection after an error with autocommit=false James Im <im-james@hotmail.com>
2007-02-20 10:50 ` Heikki Linnakangas <heikki@enterprisedb.com>
2007-02-28 20:41 ` Tim Pizey <timp@melati.org>
2007-02-28 22:33 ` Dave Cramer <pg@fastcrypt.com>
2007-03-01 20:59 ` Tim Pizey <timp@melati.org>
2007-02-20 10:53 ` Altaf Malik <mmalik_altaf@yahoo.com>
2007-02-20 15:39 ` Scott Marlowe <smarlowe@g2switchworks.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox