*
The moose likes JDBC and the fly likes Obtaining unique user ids Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Obtaining unique user ids" Watch "Obtaining unique user ids" New topic
Author

Obtaining unique user ids

anuj sahai
Greenhorn

Joined: Dec 02, 2000
Posts: 8
In my application i have to give each user who logs into the appliation a unique transaction id. for this the requiremnt is to obtain the max value from a DB2 table, increment it and the insert it. The problem is that incase another user also logs in the sametime he/she has to be provided a unique id. to ensure his i feel that i would need to implement a table level lock. However this would make it highly ineficent i the case of heavy traffic and causing timeout for many users.
Please suggest how should such a case be handled.
I am using jdbc and backend is db2 v6.1...
Shane
Greenhorn

Joined: Jan 25, 2002
Posts: 2
I would write a method to generate a unique string identifier. First generate a large random number . Make sure it has a large range of output. Then use " ref = new StringBuffer(Long.toString(strNum))" to convert it and pass it to a StringBuffer object. Randomly insert a few chars into the string and use ref.toString() again before sending to your table. Or, if you wanted to make things a bit easier, use System.currentTimeMillis() to obtain a long which won't be duplicated unless System.currentTimeMillis() is called w/in the same millisecond. The first solution may seem like a hack but I have used this several times effectively especially with a lot of simultaneous traffic. It is possible to issue a duplicate w/ the first but if you write the method well it will be next to impossible. Hope this helps
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Shane",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please re-register and select a new name which meets the requirements.
Thanks.
On a personal note, its nice to see someone come out of the blocks answering questions rather than asking them, it's appreciated.
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Obtaining unique user ids
 
Similar Threads
multiple request to severs from multiple users
Hibernate on DB's w/o Primary Keys
diferents types of users
Struts Exception handling
JPA (TopLink) DB2 table generation