Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2003
    Posts
    5

    Unanswered: Assigning sequence value to a variable

    Hello experts,
    I have a very simple question, being a new DB2 developer.
    I need to assign NEXTVAL of an existing sequence to a variable in my Java program and then run DML statements on multiple tables using this variable. I'm not allowed to use SYSDUMMY1 pseudo table in the current environment.

    What is the best way to do this ? If you can show me a sample assignment statement, that would be highly appreciated.

    Thanks !

  2. #2
    Join Date
    Jul 2003
    Location
    Austin, TX, USA
    Posts
    278

    Try.

    Hi,

    You can use select from sysibm.syssequences. Put that in a string

    for eg.. String Seq = (returned resultset.next)

    This would help.

    I dunno much of java, but this is how our guys do it.

    HTH

    Nitin.

  3. #3
    Join Date
    Dec 2003
    Posts
    5
    Nitin,
    Thanks for taking time to answer my question.
    I still don't know whether your solution would solve my problem.

    Selecting from sysibm.syssequences will not be equivalent to using NEXTVAL, which actually would increment/decrement the sequence number automatically. Your solution would allow me to find the last generated value, but I can't use it as a method to generate my sequence automatically.

    Please help me understand where I am going wrong.

    Thanks !

  4. #4
    Join Date
    Dec 2003
    Location
    Columbia, SC
    Posts
    9

    Re: Assigning sequence value to a variable

    can anyone help me in getting the "Fmpjdbc12.jar" file. I am desperately looking for that.
    Please some one help me out in this regard.
    Reply me back to pbharath_iitm@yahoo.co.in

    Thanks,
    Bharath

    Originally posted by harik
    Hello experts,
    I have a very simple question, being a new DB2 developer.
    I need to assign NEXTVAL of an existing sequence to a variable in my Java program and then run DML statements on multiple tables using this variable. I'm not allowed to use SYSDUMMY1 pseudo table in the current environment.

    What is the best way to do this ? If you can show me a sample assignment statement, that would be highly appreciated.

    Thanks !

  5. #5
    Join Date
    Dec 2003
    Posts
    5
    Bharat,
    You have posted your question as a thread to my discussion, which is totally un-related. Please delete it from here and post it as as a new discussion thread, so that people can answer your question.

    Thanks !

  6. #6
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Does

    db2 "VALUES(nextval for sequence1)"

    help ?

    Cheers
    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  7. #7
    Join Date
    Dec 2003
    Posts
    5
    Sathyaram,
    The command works, I know, but how do you assign that value to a variable within your program?

    Thanks !

  8. #8
    Join Date
    Nov 2003
    Location
    Netherlands
    Posts
    96
    Originally posted by harik
    Sathyaram,
    The command works, I know, but how do you assign that value to a variable within your program?

    Thanks !
    values (nextval for ..) into :hostvariable

    This works on DB2 unix/Windows, I'm not sure it will also work on DB2 OS/390 (and don't forget to read the manual ).

    Hope this helps.

  9. #9
    Join Date
    Dec 2003
    Posts
    5
    Thanks for the tip. Eventhough this is not exactly what I was looking for, your answer opened up another possibility for me.

    I appreciate your help !!
    Thanks to every on who participated in this thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •