concurrency problem - Mailing list pgsql-sql

From sathish kumar shanmugavelu
Subject concurrency problem
Date
Msg-id ee0ad3a30606152114g122d0021ja7c603a8f36ae62c@mail.gmail.com
Whole thread Raw
Responses Re: concurrency problem
Re: concurrency problem
Re: concurrency problem
List pgsql-sql
Dear group,<br />    Let me explain my issue.<br />       We use<br />              Database      - postgresql-8.1<br
/>             JDBC Driver  - postgresql-8.1-407.jdbc3.jar<br />              Java             - jdk1.5<br />          
  The default transaction isolation level is - Read Committed <br />              Auto Commit is false<br />    In our
applicationwe used a single connection object. We open the connection in the MDI form and close it only when the MDI
closes, simply when the application closes. <br />    I give a insert statment like <br />             INSERT INTO
rcp_patient_visit_monitor(<br />                   entry_no, patient_id, visit_date, is_newpatient, visit_type,
is_medical,<br />                   is_review, is_labtest, is_scan, is_scopy, is_xray, weight, height) <br
/>                  VALUES (<span style="font-weight: bold;">(SELECT coalesce(max(entry_no)+1, 1)</span> FROM
rcp_patient_visit_monitor),?,current_timestamp,?,?,?,?,?,?,?,?,?,?)<br/>       <br />    The point to note here is the
selectstatement which gets the max entry_no and adds one to it and save the new value. entry_no is the primary key of
theabove table. <br />    <br />   Now i run the same program (different instance) from two systems, save the form
simultaneously,only one entry is saved, in the other system the error says - duplicate key violates.<br /><br />   If i
usethe transaction level - Serializable - again one entry is saved. Only on closing this application (closing the
connection)the application running in other system is getting saved. <br /> <br />   If i lock the table and create a
transaction- by sending the commands <br />         con.createStatement().executeUpdate("begin");<br />        
con.createStatement().executeUpdate("locktable rcp_patient_visit_monitor"); <br />         int rows =
psSave.executeUpdate();<br/>         con.createStatement().executeUpdate("commit");<br />   <br />   The form in one
systemis saved, in another system an error says - ' Deadlock detected  .....' <br />   <br />    When i test the above
saidcommands in dbvisualizer from two different systems , it works, but here it does not. why.<br />   <br />    how to
solvethis concurrency problem.<br /><br />Thanks in advance,<br />-- <br /> Sathish Kumar.S<br />SpireTEK  

pgsql-sql by date:

Previous
From: "Phillip Smith"
Date:
Subject: Re: listen_addresses = '*' ok, specific address(es) no (.... and a thread hi-jack!)
Next
From: Richard Huxton
Date:
Subject: Re: concurrency problem