Thread: Transactions through JDBC

Transactions through JDBC

From
"Albert"
Date:
Hi all!

Actually I have a client-server application with one server and many
clients each one of which opens a different connection to the postgres
database. In order to avoid those known problems with the execution of
the different clients' operations at database, I implemented
everything in this way. Each operation is made so:

conn.executeUpdate("BEGIN");
conn.execute(...)
conn.execute(...)
conn.execute(...)
conn.executeUpdate("COMMIT");

May it be considered right, or am I making something wrong? I use JDBC
driver for postgres 8.1

Thanks!


Re: Transactions through JDBC

From
"Alberto Molteni"
Date:
>You should use

>  conn.setAutoCommit(false);
>  conn.execute(...)
>  conn.execute(...)
>  conn.execute(...)
>  conn.commit();

>
> Thanks!

jan

Then,  conn.setAutoCommit(false); has to be regarded as a begin statement?
I had already put the autocommit flag to false soon after the creation of
the connection, since I saw an improvement in the performances without that
flag and moreover I wanted to make transactions on my own.

I will change as you told me!

Thanks!








>
>
> ---------------------------(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



--
--------------------------------------------------------------
Jan de Visser jdevisser@digitalfairway.com

Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------


Re: Transactions through JDBC

From
"Jan de Visser"
Date:
On Wednesday 11 April 2007 14:01:55 Alberto Molteni wrote:
> >You should use
> >
> >  conn.setAutoCommit(false);
> >  conn.execute(...)
> >  conn.execute(...)
> >  conn.execute(...)
> >  conn.commit();
> >
> >
> > Thanks!
>
> jan
>
> Then,  conn.setAutoCommit(false); has to be regarded as a begin statement?

I think BEGIN is implicitly send when you execute the first statement in a new
transaction. You shouldn't worry about it.

> I had already put the autocommit flag to false soon after the creation of
> the connection, since I saw an improvement in the performances without that
> flag and moreover I wanted to make transactions on my own.

Makes sense.

>
> I will change as you told me!
>
> Thanks!

jan

--
--------------------------------------------------------------
Jan de Visser                     jdevisser@digitalfairway.com

                Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------

Re: Transactions through JDBC

From
"Jan de Visser"
Date:
On Wednesday 11 April 2007 12:49:49 Albert wrote:
> Hi all!
>
> Actually I have a client-server application with one server and many
> clients each one of which opens a different connection to the postgres
> database. In order to avoid those known problems with the execution of
> the different clients' operations at database, I implemented
> everything in this way. Each operation is made so:
>
> conn.executeUpdate("BEGIN");
> conn.execute(...)
> conn.execute(...)
> conn.execute(...)
> conn.executeUpdate("COMMIT");
>
> May it be considered right, or am I making something wrong? I use JDBC
> driver for postgres 8.1


You should use

  conn.setAutoCommit(false);
  conn.execute(...)
  conn.execute(...)
  conn.execute(...)
  conn.commit();

>
> Thanks!

jan

>
>
> ---------------------------(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



--
--------------------------------------------------------------
Jan de Visser                     jdevisser@digitalfairway.com

                Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------