Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aXOdH-0006TK-IW for pgsql-jdbc@arkaria.postgresql.org; Sun, 21 Feb 2016 07:40:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aXOdG-0007Mc-HI for pgsql-jdbc@arkaria.postgresql.org; Sun, 21 Feb 2016 07:40:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aXOcl-0006nj-KR for pgsql-jdbc@postgresql.org; Sun, 21 Feb 2016 07:40:11 +0000 Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aXOcg-0005Rk-VH for pgsql-jdbc@postgresql.org; Sun, 21 Feb 2016 07:40:10 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aXOcd-0004wU-P3 for pgsql-jdbc@postgresql.org; Sun, 21 Feb 2016 08:40:03 +0100 Received: from ppp-46-244-214-50.dynamic.mnet-online.de ([46.244.214.50]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Feb 2016 08:40:03 +0100 Received: from spam_eater by ppp-46-244-214-50.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Feb 2016 08:40:03 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: JDBC behaviour Date: Sun, 21 Feb 2016 08:39:48 +0100 Lines: 29 Message-ID: References: <4C508581-9CA3-490D-A376-CC1F9FF5D258@me.com> <56C8487F.7020406@hogranch.com> <20160220111625.4ee764661333e42e230348ad@potentialtech.com> <20160220120901.58bea0d780fad45775f04bfa@potentialtech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp-46-244-214-50.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Sridhar N Bamandlapally schrieb am 21.02.2016 um 03:20: > Hi > > My expectation is simple, please refer below > > create table employee(empid numeric(4) primary key, ename varchar(20)); > > from Java/jdbc code, conn.setAutoCommit(false) > > insert into employee values(1, 'K1'); > insert into employee values(1, 'K1'); > insert into employee values(2, 'K2'); > > by looking at exceptions i may rollback or commit, i.e. conn.rollback() or conn.commit() > if I rollback table should be empty, > if I commit table should have 2 rows > > is there any way is possible ? Use on conflict do nothing: insert into employee values(1, 'K1') on conflict (empid) do nothing; insert into employee values(1, 'K1') on conflict (empid) do nothing; insert into employee values(2, 'K2') on conflict (empid) do nothing; This can be combined with a PreparedStatement and batching if needed. -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc