473,569 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to generate unique no. with java and mysql

I need to generate a unique no. in the format like
yyyymmddxxxxxx (xxxxxx 6-digitl running number)

I think of create a table with two columns

date value
20050405 120
20050406 99

Everytime, the application will increase the value+1 based on the same
date. If not date found, create one record and value = 1

The problem is that since there's no transaction at mysql 4.1.x that
even the application
1. insert value
2. max() to get
max() may not get the value just insert BECAUSE there may be
MULTI-threads/users

How can implement so with Java and mysql?
Jul 23 '05 #1
2 3223
You could use a transaction-safe MySQL storage engine like InnoDB.

Jul 23 '05 #2
"Mullin" wrote:
I need to generate a unique no. in the format like
yyyymmddxxxxxx (xxxxxx 6-digitl running number)

I think of create a table with two columns

date value
20050405 120
20050406 99

Everytime, the application will increase the value+1 based on
the same
date. If not date found, create one record and value = 1

The problem is that since there's no transaction at mysql
4.1.x that
even the application
1. insert value
2. max() to get
max() may not get the value just insert BECAUSE there may be
MULTI-threads/users

How can implement so with Java and mysql?


Create an auto-incrementing primary key field, and insert into it, and
grab the just incremented number back. This is always unique, even if
multiple processes are accessing.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/mySQL-genera...ict212741.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=729728
Jul 23 '05 #3

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

Similar topics

10
18563
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from tablename; Here this function generate unique id for each row of the table. Regards..
1
11232
by: hikums | last post by:
I am posting this here, just in case anyone may need this. Step 1: CREATE SEQUENCE ID_SEQ START WITH 1050000 INCREMENT BY 1 MAXVALUE 9999999 NO CYCLE NO CACHE ORDER
29
3718
by: Lauren Wilson | last post by:
Does anyone know how the following info is extracted from the user's computer by a Front Page form? HTTP User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 I only ask because I believe I could use the same info as part of a scheme to generate a unique (or at least less common) serialized id...
28
17664
by: Nina | last post by:
I need to generate unique id for my application. Use system time to create id, which is the best fit, but I don't know how to do it. Please help. Thanks in advance for any input.
1
9722
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a grinview/formview etc.): <DbProviderFactories> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data...
15
37569
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code Different-2 string.
4
2833
by: gaurav1983 | last post by:
i have to generate unique combinations of given number of digits entered by user eg: N=4 (0,1,2,3) output should be 0 1 2 3
1
2741
by: situ | last post by:
Hi, I'm using DB2 V9 for windows I'm inserting records into DGTT from select statement; the problem is how to insert unique value for every row inserted. I tried using “generated always as” clause but its exhausting at some point of time. Say if 100000 records were needed to be processed, it’s only processing up to 60000 rows.
6
2023
by: er | last post by:
hi, here's why i'm trying to do: header1.hpp namespace{ struct A{};} struct B1{ A a; }; header2.hpp namespace{ struct A{};}
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
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...
0
6287
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...
0
5223
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...
0
3657
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.