Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9ECA1475F4F for ; Mon, 30 Dec 2002 12:28:35 -0500 (EST) Received: from chlothar.bnv-bamberg.de (chlothar.bnv-bamberg.de [217.146.130.193]) by postgresql.org (Postfix) with ESMTP id A5389475CC7 for ; Mon, 30 Dec 2002 12:28:34 -0500 (EST) Received: from pd951d305.dip.t-dialin.net ([217.81.211.5] helo=perry.meinl.bnv-bamberg.de) by mail.bnv-bamberg.de with esmtp id 18T3iP-0003cP-00 ; Mon, 30 Dec 2002 18:28:37 +0100 Received: from meinl.bnv-bamberg.de (gucky.meinl.bnv-bamberg.de [192.168.0.2]) by perry.meinl.bnv-bamberg.de (Postfix) with ESMTP id 5E6565CF49; Mon, 30 Dec 2002 18:28:37 +0100 (CET) Message-ID: <3E10825A.9000608@meinl.bnv-bamberg.de> Date: Mon, 30 Dec 2002 18:28:58 +0100 From: Thorsten Meinl User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.2.1) Gecko/20021130 X-Accept-Language: en, de MIME-Version: 1.0 To: "Campano, Troy" Cc: pgsql-jdbc@postgresql.org Subject: Re: batch example References: <82C3FD729CFA504CA44E7D32BDED411FBD378A@LM-EXMSG-07.lm.lmig.com> In-Reply-To: <82C3FD729CFA504CA44E7D32BDED411FBD378A@LM-EXMSG-07.lm.lmig.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/237 X-Sequence-Number: 5850 Hello Troy, > Can someone point me to an example using a batch statement for > Postgresql? > Maybe this helps... Don't be confused about the creation of the SQL-Statements, the point is "sth.addBatch" and "sth.executeBatch". public void saveChanges() throws SQLException { if (! dataChanged) return; Statement sth = PDMObject.this.con.createStatement(); for (int i = 0; i < attributeCount; i++) { try { if (attributes[i].isNew()) { sth.addBatch("INSERT INTO PDM_Spaltennamen (name, typid, text_de, text_en, text_fr, pos, menueIndex) VALUES (" + "'" + attributes[i].getName() + "', " + "(SELECT id FROM PDM_Typen WHERE (objektTyp = '" + relationName + "')), " + ((attributes[i].getText("de") != null) ? ("'" + attributes[i].getText("de") + "'") : "NULL") + ", " + ((attributes[i].getText("en") != null) ? ("'" + attributes[i].getText("en") + "'") : "NULL") + ", " + ((attributes[i].getText("fr") != null) ? ("'" + attributes[i].getText("fr") + "'") : "NULL") + ", " + + attributes[i].getPosition() + ", " + 0 + ")" ); } else { sth.addBatch("UPDATE PDM_Spaltennamen SET " + ((attributes[i].getText("de") != null) ? ("text_de = '" + attributes[i].getText("de") + "'") : "text_de = NULL") + ", " + ((attributes[i].getText("en") != null) ? ("text_en = '" + attributes[i].getText("en") + "'") : "text_en = NULL") + ", " + ((attributes[i].getText("fr") != null) ? ("text_fr = '" + attributes[i].getText("fr") + "'") : "text_fr = NULL") + ", " + "pos = " + attributes[i].getPosition() + ", " + "menueIndex = " + 0 + " WHERE (name = '" + attributes[i].getName() + "') AND " + "(typid = (SELECT id FROM PDM_Typen WHERE (objekttyp = '" + relationName + "')))" ); } } catch (WrongArgumentException e) { // sollte nicht passieren, sonst Programmierfehler e.printStackTrace(); } } sth.executeBatch(); sth.close(); dataChanged = false; } Greetings Thorsten