Unix Technical Forum

Re: how to use transaction isolation

This is a discussion on Re: how to use transaction isolation within the Pgsql General forums, part of the PostgreSQL category; --> On 4/10/08, Gong <fredkung@sohu.com> wrote: > > > In the java code below, I set the transaction isolation to ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 01:53 AM
Jan de Visser
 
Posts: n/a
Default Re: how to use transaction isolation

On 4/10/08, Gong <fredkung@sohu.com> wrote:
>
>
> In the java code below, I set the transaction isolation to serialization.
>
> public class IsolationTest {
>
> private static String select = "select * from tmp where url = 'aaa'";
>
> public static void main(String[] args) throws Exception{
> //ConncetionFactory is a factory class for managing connection
> Connection con = ConnectionFactory.getConnection();
>
>
> con.setTransactionIsolation(Connection.TRANSACTION _SERIALIZABLE);
> con.setAutoCommit(false);
>
> Statement smt = con.createStatement();
> ResultSet r1 = smt.executeQuery(select);
> System.out.println(r1.next()); //(1)
> con.commit(); //(2)
>
> ResultSet r2 = smt.executeQuery(select);
> System.out.println(r2.next()); //(3)
> con.commit();
> smt.close();
>
> ConnectionFactory.closeConnection();
> }
> }
>
> I set a break point at (2), then I run this code in debug mode. When it
> suspended at (2), line(1) print "false". Then, I execute an insert statement
> in pgadmin: insert into tmp values('aaa'), after that I continued to run the
> code, and line(3) print "true". I have set the transaction isolation to
> serialization, didn't the two select statements print the same result?


Your commit at (2) ends the transaction, and the second select runs in
a new one.

jan

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2008, 02:05 AM
Gong
 
Posts: n/a
Default Re: how to use transaction isolation


On 4/11/08, Jan de Visser <jdevisser@digitalfairway.com> wrote:

>Your commit at (2) ends the transaction, and the second select runs in
>a new one.


>jan


--
I got it. I didn't notice it is the *TRANSACTION* isolation.
Thanks a lot!


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:43 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com