File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to generate Auto-EIN number in db ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to generate Auto-EIN number in db ?" Watch "How to generate Auto-EIN number in db ?" New topic
Author

How to generate Auto-EIN number in db ?

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
Hi,

What i want, whenever an admin register a new user by filling up his/her details(except EIN) it should be saved in the database(iam using sql server 2005) but with Auto-generated EIN with the format say 'P1000'.
Now when admin registers another one, it should be saved with 'P1001'. Please give me some idea in order to achieve this.

My first question is , i have a primary key field in db 'ein' to store all the EINs. What should be the type of that field. Is it going to be 'Varchar' or simple 'Int' ?
And also onLoad of the registeration page, an action will be called automatically to get the latest EIN increament by 1 in an computed text, so that the Admin can read what will be the next EIN going to be registered.

Now how can i separate 'P' and '1000' from 'P1000' , and then increment 1000 by 1 to become 'P1001' before saving it into database ?

And also let me know whether iam right in my logic or not ?


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What is an EIN? And can I ask, why is it important to preface the number with the letter P? Would a simple autoincremented surrogate key not be easier to use?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
 
subject: How to generate Auto-EIN number in db ?
 
Similar Threads
How do DB-Auto-Generated Primary Key in EJB 2.0?
jsp
There will be no jobs in america for another 2 Years
Career Advise Needed ! Urgent
Tomcat 6 admin package