HP3000-L Archives

April 2000, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Lars Appel <[log in to unmask]>
Reply To:
Lars Appel <[log in to unmask]>
Date:
Sun, 16 Apr 2000 15:40:59 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (56 lines)
Chip after Dave wrote...

>I have the same need that Dave outlined in his original post so
>I am interested in seeing any and all approaches to this problem.

>  -lock the file with waiting
>  -read the current "next number" from the file
>  -increment the current "next number"
>  -write the current "next number" back to the same record
>  -unlock the file

Can't help with ODBC, but here is a JDBC snippet that I use...

  private Connection con;  // initialized somewhere else

    ...

      con.setAutoCommit(false);

      System.err.println("increment uniquekey");
      Statement st = con.createStatement();
      st.executeUpdate(
        "update "
        + dbTableUniqueCount
        + " set dbsetcounter = dbsetcounter + 1;"
      );
      st.close();

      System.err.println("retrieve uniquekey");
      st = con.createStatement();
      ResultSet rs = st.executeQuery(
        "select dbsetcounter from "
        + dbTableUniqueCount
        + ";"
      );
      rs.next();
      String uniqueKey = rs.getString("dbsetcounter");
      rs.close();
      st.close();

      System.err.println("insert customer data (etc)");
      // details snipped for brevity

      System.err.println("insert patch list");
      // details snipped for brevity

      System.err.println("commit transaction");
      con.commit();
      con.setAutoCommit(true);

    ...

Sorry, if this is off-topic re ODBC. At least it is SQL (or close ;-)

Lars "corrections welcome"

ATOM RSS1 RSS2