Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: how to use ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 15250 of 17598
Post > Topic >>

Re: how to use transaction isolation

by jdevisser@[EMAIL PROTECTED] ("Jan de Visser") Apr 10, 2008 at 04:47 PM

On 4/10/08, Gong <fredkung@[EMAIL PROTECTED]
> 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@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 2 Posts in Topic:
Re: how to use transaction isolation
jdevisser@[EMAIL PROTECTE  2008-04-10 16:47:24 
Re: how to use transaction isolation
fredkung@[EMAIL PROTECTED  2008-04-11 16:39:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 8:29:55 CST 2008.