aspose file tools*
The moose likes Beginning Java and the fly likes piece of code for auto generation of numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "piece of code for auto generation of numbers" Watch "piece of code for auto generation of numbers" New topic
Author

piece of code for auto generation of numbers

narayana satish
Greenhorn

Joined: Dec 21, 2000
Posts: 25
I am doing a project in which i am using SQL as back end. I want to write a piece of code which will make autogeneration for the field PA_NO whenever if i add the record to back end.
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Hi, Narayana.
If you have no objection to sequentially assigned prime keys (1, 2, 3, etc.), then simply do a SELECT MAX() against your database table's prime key. If nothing is returned (i.e., that table has no rows), set the prime key to 1. If you get a value back from SELECT MAX(), add 1 to it to generate your next prime key.
Of course, to prevent prime key duplication (a BIG no-no), you'll have to make these processes synchronized.
Good luck, and I hope this helps,
Art
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: piece of code for auto generation of numbers
 
Similar Threads
write and append with same streams.
Abstraction
storing an object into session variable
Whatcha reading?
Functional Point Analysis for PLSQL batches