473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

autonumber generation

52
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 3777
Ganon11
3,652 Expert 2GB
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 8TB
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
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 Expert 2GB
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
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 100+
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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...

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.