It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Generating primry keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Generating primry keys" Watch "Generating primry keys" New topic

Generating primry keys

Piradharsan Navaratnam

Joined: May 15, 2007
Posts: 14
Friend How can I create unique primary keys in java or in mysql.

Please read this...........

There are lot of speed posts(type of mail/letter) are accepted in our postoffices. I need to uniquely identify them. I thought to generate a unique id like this.

Say its 04thJune07 then
the ids will propogate like 040607(a unique post office id - 5 digits)(auto increment letter id)

For example 040607907361
040607 is the date, 90736 is the post office code (there are unique code for every post offices), 1 is the autoincrement no.

Can any body help me?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

This post has been moved to a more appropriate forum.

[Asking smart questions] [About Bear] [Books by Bear]
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Here's a Google search command that searches the official mysql site for autoincrement within a CREATE TABLE SQL command:

create table autoincrement

It is sorta covered in the JavaRanch Style Guide.
subject: Generating primry keys
It's not a secret anymore!