If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Assigning sequence value to a variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-03, 18:06
harik harik is offline
Registered User
 
Join Date: Dec 2003
Posts: 5
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 !
Reply With Quote
  #2 (permalink)  
Old 12-15-03, 02:21
nitingm nitingm is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 12-15-03, 10:19
harik harik is offline
Registered User
 
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 !
Reply With Quote
  #4 (permalink)  
Old 12-15-03, 10:26
bharath28 bharath28 is offline
Registered User
 
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

Quote:
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 !
Reply With Quote
  #5 (permalink)  
Old 12-15-03, 10:45
harik harik is offline
Registered User
 
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 !
Reply With Quote
  #6 (permalink)  
Old 12-15-03, 19:30
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Does

db2 "VALUES(nextval for sequence1)"

help ?

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #7 (permalink)  
Old 12-16-03, 16:52
harik harik is offline
Registered User
 
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 !
Reply With Quote
  #8 (permalink)  
Old 12-16-03, 17:31
GertK GertK is offline
Registered User
 
Join Date: Nov 2003
Location: Netherlands
Posts: 96
Quote:
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.
Reply With Quote
  #9 (permalink)  
Old 12-22-03, 13:56
harik harik is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On