X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 8DD319FA5C8 for ; Fri, 16 Jun 2006 03:15:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 31766-01 for ; Fri, 16 Jun 2006 03:15:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 8056B9F9CAA for ; Fri, 16 Jun 2006 03:15:40 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 25E6F30925; Fri, 16 Jun 2006 08:15:39 +0200 (MET DST) From: "sathish" X-Newsgroups: pgsql.interfaces.jdbc Subject: concurrency problem Date: 15 Jun 2006 23:15:32 -0700 Organization: http://groups.google.com Lines: 55 Message-ID: <1150438532.415247.30420@p79g2000cwp.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 ceedees:3128 (squid/2.5.STABLE9), 1.0 gateway.ready-link.org:3128 (squid/2.5.STABLE5-CVS) Complaints-To: groups-abuse@google.com Injection-Info: p79g2000cwp.googlegroups.com; posting-host=203.101.67.2; posting-account=FVNZLA0AAACvvuBT5OlRxfqK4g4y_2B8 To: pgsql-jdbc@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/37 X-Sequence-Number: 15317 Dear group, Let me explain my issue. We use Database - postgresql-8.1 JDBC Driver - postgresql-8.1-407.jdbc3.jar Java - jdk1.5 The default transaction isolation level is - Read Committed Auto Commit is false In our application we 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. I give a insert statment like INSERT INTO rcp_patient_visit_monitor ( entry_no, patient_id, visit_date, is_newpatient, visit_type, is_medical, is_review, is_labtest, is_scan, is_scopy, is_xray, weight, height) VALUES ((SELECT coalesce(max(entry_no)+1, 1) FROM rcp_patient_visit_monitor),?,current_timestamp,?,?,?,?,?,?,?,?,?,?) The point to note here is the select statement which gets the max entry_no and adds one to it and save the new value. entry_no is the primary key of the above table. 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. If i use the 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. If i lock the table and create a transaction - by sending the commands con.createStatement().executeUpdate("begin"); con.createStatement().executeUpdate("lock table rcp_patient_visit_monitor"); int rows = psSave.executeUpdate(); con.createStatement().executeUpdate("commit"); The form in one system is saved, in another system an error says - ' Deadlock detected .....' When i test the above said commands in dbvisualizer from two different systems , it works, but here it does not. why. how to solve this concurrency problem. Also i want to know if a table is locked from jdbc. Thanks in advance, -- Sathish Kumar.S SpireTEK