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.
6 3777
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.
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 - if(tableName.equalsIgnoreCase("Client")) { //generating for the client table
-
int previous = Integer.parseInt(genL.getClient());// If key is a String
-
generateTable.setClient(""+(previous + 1));
-
ref = "A";
-
if((previous + 1) < 10) {
-
ref += "0";
-
}
-
ref = ref + "" + (previous + 1);
-
}
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.
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |