473,470 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

autonumber generation

52 New Member
hi,

i need to automatically generate a sequential number for each record that i insert into the database from my jsp page. how do i do this? im using oracle as my database.
Mar 9 '07 #1
6 3780
Ganon11
3,652 Recognized Expert Specialist
By sequential, you mean the first will have the number 1, the second will have 2, the eighty-second will have 82, etc?

How are you inserting the records? You can use a static variable initialized to 1 to start - this is the record's number. Every time you finish adding a record, increment the variable.
Mar 9 '07 #2
r035198x
13,262 MVP
By sequential, you mean the first will have the number 1, the second will have 2, the eighty-second will have 82, etc?

How are you inserting the records? You can use a static variable initialized to 1 to start - this is the record's number. Every time you finish adding a record, increment the variable.
Write a utility method called generateRefNumber. You can then put it in a servlet and call it everytime you create a record in the DB. Create a table in your database called Generated and use it to store the value of the last generated ref number. If you need to generate say, 5 sequential non-interleaving refNumbers then that bean would have 6 fields(the other for the key)
Your generate ref would then look something like this


Expand|Select|Wrap|Line Numbers
  1.  if(tableName.equalsIgnoreCase("Client")) { //generating for the client table
  2.     int previous = Integer.parseInt(genL.getClient());// If key is a String
  3.     generateTable.setClient(""+(previous + 1));
  4.     ref = "A";
  5.     if((previous + 1) < 10) {
  6.      ref += "0";
  7.     }
  8.     ref = ref + "" + (previous + 1);
  9.    } 
Mar 9 '07 #3
cwfent
14 New Member
I was wondering if anyone could help me out with this problem. I have a script that has a bunch of code in it. For some reason the coder decided to use a hex for a id number (it's just a member number, nothing secret) anyway the code section that I want to change is this :

function createUniqueID($table, $column)
{
$maxTries = 10;

while(1)
{
if($maxTries <= 0)
return false;

$uniqueID = substr(md5(uniqid(rand(), true)), 0, 8);

// check if this token does not exist in the table already
$sql = "select $column from $table where $column="._q($uniqueID);
$rs = (directory where code is located)::execute($sql, __FILE__, __LINE__);
if(!$rs)
{
showMsg(L_G_DBERROR, 'error');
return false;
}

if($rs->EOF)
return $uniqueID;

$maxTries--;
}

return false;
}

I just want a 5 digit sequential number. Can someone tell me how to change this. I realize that auto_increment would work in the db, but, there is so much code that interrelates in the script I don't believe that removing this string would work properly. Thanks for any help.
Sep 10 '07 #4
Ganon11
3,652 Recognized Expert Specialist
1) This is not a Java related question, which I can tell from those $'s all over the place. This is the Java forum. Please find the proper forum to ask your question in.

2) This is someone else's thread; please ask your questions in your own thread.
Sep 10 '07 #5
cwfent
14 New Member
1) This is not a Java related question, which I can tell from those $'s all over the place. This is the Java forum. Please find the proper forum to ask your question in.

2) This is someone else's thread; please ask your questions in your own thread.

Hi,

I'm sorry I did a general forum search and found the thread about sequential number sequence. I hadn't noticed it was in a Java section and I thought I was allowed to ask a question about the same problem, which I thought it was. I am sorry for the inconvenience and have asked the question in the appropriate section with my own thread.
Sep 10 '07 #6
kreagan
153 New Member
hi,

i need to automatically generate a sequential number for each record that i insert into the database from my jsp page. how do i do this? im using oracle as my database.
Why don't you do this using your database? Databases have the ability to auto-increment a field for every row. This increment is autonomous and specific for each table.

In java, you can just keep a static global veriable which increments every time you generate an new insert.
Sep 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

33
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and...
2
by: Ed Havelaar | last post by:
Hi, Hope someone can help. Here's the scenario: I have two MSAccess tables MainTab and SubTab. MainTab has an autonumber 'id' column as primary key. Subtab has this id column as a foreign...
7
by: Bob | last post by:
Hi Everybody I have a query that is based on table that I need to have some sort of Unique ID # for. I can't have a unique ID in the table, but the table DOES have a date field and I'm working...
35
by: Traci | last post by:
If I have a table with an autonumber primary key and 100 records and I delete the last 50 records, the next record added would have a primary key of 101. Is there any way to have the primary key...
2
by: Steve | last post by:
I have a database where I want to use an autonumber field to make SKUs for a new product when it is entered. Is there a way I can make the field zero fill to a certain length? For instance, if I...
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
26
by: jimfortune | last post by:
Sometimes I use Autonumber fields for ID fields. Furthermore, sometimes I use those same fields in orderdetail type tables. So it's important in that case that once an autonumber key value is...
5
by: ndn_24_7 | last post by:
Hello all, I'm designing a incident reporting program that allows our security department to record incidents. The problem i'm having is on a form, when ever a user is going to add a new...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.