473,769 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

auto increment primary key val into XML attribute

Chaps,

I'm starting to play with db2 V9.1 and am writing a stored procedure
to manage accounting records from oiur RADIUS server.

I've got an XML aware table with an auto increment primary key, a few
sql columns and an XML column. For every XML object I'm inserting, i'd
lke to have an ID attribute that has the same value as the SQL primary
key that'll be created upon executing the insert.

Is there any way in my Java stored procedure I can get hold of what the
"next" primary key will be so that I can do the above.

Of course I could cheat and insert the sql primary key into the
attribute when i retrieve the data, but that would stop me doing other
things

TIA

alex

Aug 25 '06 #1
2 8711
alexs,

if I undestand it correctly, you would like to have the ID before you
insert the record (in order to compose XML attribute).

Use sequence, and in your stored procedure just generate the next value
before you insert the record:

CREATE SEQUENCE seq1 AS BIGINT
VALUES NEXTVAL INTO id FOR seq1

-- Artur Wronski

Aug 26 '06 #2
hi,
o.k. think I'm missing something here.

1).
If I've defined the primary key for a table to be auto increment then
surely you can't insert a value into it that's generated by the stored
procedure.

2). If the primary key isn't auto increment, and i generate the key
value from within a stored procedure using a create sequence statement,
what happens if I update the sp, or the instrance is restarted, If i've
got pirmary keys in the range 1 - 99 and i stop and start the database,
how does the create sequence statement know to start from 100 and not
1 ?

It sort of assumes that at some point when the sp is being initialized
you do some magic to find out what the next primary key value is and
use that to init your sequence

Artur wrote:
alexs,

if I undestand it correctly, you would like to have the ID before you
insert the record (in order to compose XML attribute).

Use sequence, and in your stored procedure just generate the next value
before you insert the record:

CREATE SEQUENCE seq1 AS BIGINT
VALUES NEXTVAL INTO id FOR seq1

-- Artur Wronski
Aug 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
5673
by: Nick | last post by:
Is it possible to have multiple auto increments in one column? Say I have two tables... 1. table 'messageboards' with fields ('id' , 'name') 2. table 'messagethreads' with fields ('id' , 'messagethread' , 'messageboard_id') The 'messagethreads.id' column could have multiple auto increments. Then I could easily query a messageboard with ("SELECT * FROM
2
2198
by: David P. Donahue | last post by:
I'm using the following code to add a row to a table (for holding images) in my database (obtained from http://www.codeproject.com/aspnet/image_asp.asp?df=100&forumid=38225&select=1038401): public string AddImage(byte buffer, string contentType) { string strSql = "SELECT * FROM WebImages"; DataSet ds = new DataSet("Image"); OdbcDataAdapter tempAP = new OdbcDataAdapter(strSql, this._objConn); OdbcCommandBuilder objCommand = new...
3
3581
by: Poul Møller Hansen | last post by:
Hi, I need an auto incrementing field that will contain values like N000001, N000002, N000003 etc. I think the way is to use the value from an identity field in a stored procedure that is triggered at insert. I can't see that it can be made in pure SQL, but Java is not a problem. Any of you that can tell me the way of doing it ?
6
5072
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
2
20199
by: David Veeneman | last post by:
I am using the "1.0.*" pattern to auto-increment the AssemblyVersion attribute of my project's assembly. I'd like to have the assembly's AssemblyFileVersion attribute match this value, so that I can see the assembly version in the Windows XP Explorer. In other words, I'd like to synchronize the file version of an assembly to its assembly version. I've discovered that the "1.0.*" pattern doesn't work for the AssemblyFileVersion attribute. ...
5
2484
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the primary key in the "suspended_table" is an auto incremented integer where as "live_table" primary key is just a standard integer. Here's the life-cycle: 1. Record gets entered into "suspended_table" 2. Record checked and then inserted into...
13
4728
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when i type in the details. I have just moved over to mysql server with access as the front end. I have setup the sql tables with the customer number as autonumber. When i go into the form and add a new customer it does not generate the
1
3129
by: rhepsi | last post by:
hii all, i have created a database with a table with number of fields....in msaccess ive set primary key as SNo: and its datatype as auto number... How to set the auto increment ???? For ex:
5
8101
by: David Wright | last post by:
Hello Everyone I would be grateful if someone could help me with the automatic increment of a field on my subform called ‘Test_SrNo’. I am Using Microsoft Office 2000. The auto entry of the incremented number would help to reduce errors and make data entry simpler. The next record in the Test_SrNo field should not have any entry in it until the text insertion point enters the Test_SrNo field. Example: If the last test serial number...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.