From: | "Jan de Visser" <jdevisser(at)digitalfairway(dot)com> |
---|---|
To: | Gong <fredkung(at)sohu(dot)com> |
Cc: | postgre-gneral <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: how to use transaction isolation |
Date: | 2008-04-10 20:47:24 |
Message-ID: | 1159c1e90804101347h46b94a82icb67932d418f7610@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 4/10/08, Gong <fredkung(at)sohu(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Joey K. | 2008-04-10 20:48:25 | Re: Can´t connect but listen address and pg_hba configured correctly |
Previous Message | Jan de Visser | 2008-04-10 20:38:43 | Re: how to use transaction isolation |