Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38080

Re: programming...?

Newsgroups comp.lang.java.programmer
Date 2018-02-22 06:23 -0800
References (8 earlier) <369426df-6367-4040-9799-dcf91f2bb1ba@googlegroups.com> <p6kalc$psr$1@news.albasani.net> <0cf6b78f-a709-4325-93f0-3012aedff160@googlegroups.com> <p6kneq$tce$1@news.albasani.net> <p6la8m$1ete$1@gioia.aioe.org>
Message-ID <d3d8fe28-7e39-446c-ace0-28955ba13e5e@googlegroups.com> (permalink)
Subject Re: programming...?
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


On Wednesday, February 21, 2018 at 9:35:16 PM UTC-5, Arne Vajhøj wrote:
> The correct way is:
> 
>       insert (musicTitle in titleTable)
>       newDBK = function_last_autogenerated_key_on_connection()
>       for all parts of work
>           insert (newDBK, partno, movementTitle) in partWorkTable.
> 
> MySQL has the function as LAST_INSERT_ID()
> 
> MS SQLServer has the function as SCOPE_IDENTiTY()
> 
> IBM DB2 has the function IDENTITY_VAL_LOCAL()
> 
> JDBC can do it database independent via Statement.getGeneratedKeys()
> 
> Arne

Getting a last ID written to increment for a new key doesn't work unless there's either a record locking method so no other process is getting the last ID until after you've written the new record, or an error check that knows you're trying to write a new record, fails if it already exists, and goes back to getting the last ID again.

In our old sequencing process we have one record contain the next sequence ID.  Then any process trying to write a new record has to lock that record (other processes can read it but cannot lock it), then write their new record, then write out the incremented sequence which releases the lock.  Of course this requires a method to release locks if a process crashes after locking before they get to releasing.  It seems like a database with an auto-sequence field that somehow recognizes the writing of new records and somehow makes the key unique for you would be easier, though it should probably return a value in case you need to care what that sequence is.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-20 07:38 -0800
  Re: programming...? Jon <jon101011@yahoo.com> - 2018-02-20 17:07 +0100
    Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-20 08:19 -0800
      Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-20 11:45 -0500
        Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-20 12:39 -0800
          Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-20 13:25 -0800
            Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-20 14:00 -0800
            Re: programming...? Daniele Futtorovic <da.futt.news@laposte.net> - 2018-02-21 00:31 +0100
            Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-20 19:24 -0500
          Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-20 19:21 -0500
  Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-20 11:41 -0500
  Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-20 19:37 +0000
    Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-20 12:10 -0800
      Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-20 22:00 +0000
  Re: programming...? Robert Spanjaard <spamtrap@arumes.com> - 2018-02-20 21:09 +0100
    Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-20 12:16 -0800
      Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-20 22:09 +0000
        Re: programming...? Robert Spanjaard <spamtrap@arumes.com> - 2018-02-21 01:16 +0100
          Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-21 00:47 +0000
            Re: programming...? Robert Spanjaard <spamtrap@arumes.com> - 2018-02-21 12:29 +0100
              Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 10:42 -0500
              Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-21 15:44 +0000
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 11:03 -0500
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-21 08:38 -0800
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 11:54 -0500
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-21 10:40 -0800
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 14:35 -0500
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-21 11:48 -0800
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-21 08:29 -0800
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 11:47 -0500
                Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-21 17:35 +0000
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 12:47 -0500
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-21 10:45 -0800
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 14:40 -0500
                Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-21 21:23 +0000
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 21:39 -0500
                Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-22 09:06 +0000
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-24 20:29 -0500
                Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-25 02:12 +0000
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-26 08:19 -0800
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-03-01 13:17 -0500
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-21 10:43 -0800
                Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-21 21:14 +0000
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-21 21:35 -0500
                Re: programming...? Kiwi User <martin@mydomain.invalid> - 2018-02-22 09:10 +0000
                Re: programming...? Eric Douglas <e.d.programmer@gmail.com> - 2018-02-22 06:23 -0800
                Re: programming...? Arne Vajhøj <arne@vajhoej.dk> - 2018-02-22 19:32 -0500

csiph-web