pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
batch example
2+ messages / 2 participants
[nested] [flat]

* batch example
@ 2002-12-30 16:22  Campano, Troy <Troy.Campano@LibertyMutual.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Campano, Troy @ 2002-12-30 16:22 UTC (permalink / raw)
  To: pgsql-jdbc@postgresql.org

Can someone point me to an example using a batch statement for Postgresql?

thank you!

Troy Campano

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: batch example
@ 2002-12-30 17:28  Thorsten Meinl <Thorsten@meinl.bnv-bamberg.de>
  parent: Campano, Troy <Troy.Campano@LibertyMutual.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Thorsten Meinl @ 2002-12-30 17:28 UTC (permalink / raw)
  To: Campano, Troy <Troy.Campano@LibertyMutual.com>; +Cc: pgsql-jdbc@postgresql.org

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-12-30 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-12-30 16:22 batch example Campano, Troy <Troy.Campano@LibertyMutual.com>
2002-12-30 17:28 ` Thorsten Meinl <Thorsten@meinl.bnv-bamberg.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox