Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Automatically Generating ID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Automatically Generating ID" Watch "Automatically Generating ID" New topic
Author

Automatically Generating ID

Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
hello All,

i want to generate RegistrationID in the Registration form.

how to do this?
Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
put this is Regestration servlet. and call it when you want to get id.

Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Suppose this is my code for Complaint Registration, then where should i put that code.



Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
You can put this code anywhere see for your edited servlet.

see for the generateId() method and randomId variable. use randomId variable where you want to use.

Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Sir, after running the same code.

Getting an error.

Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
Mohini Dhanaskar wrote:Sir, after running the same code.

Getting an error.



write throw ServletException after destroy method.
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Still showing an compile time error.
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Sir, Should i make any change in the coding also or what?
Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
Mohini Dhanaskar wrote:Sir, Should i make any change in the coding also or what?


Is it showing this error after appending my code?
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
yes,Sir
Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
try this.

Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
which database are you using?
Mohini Dhanaskar
Ranch Hand

Joined: Mar 27, 2012
Posts: 54
Sir, Oracle
Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
Check this Link

it will show you basic steps to connect to database. read full article and than start development.
Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
Also check this.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

prashant chindhade wrote:put this is Regestration servlet. and call it when you want to get id.

Prashant, I'm sure you're trying to be helpful, but please DontBeACodeMill (←click).

Also, your method (even corrected) mystifies me:
1. Why create a new Random object for each invocation? Completely unnecessary.
2. Why loop 10 times?

@Mohini:
1. If this ID is related to a database table, then I would strongly urge you to use a sequence number obtained from the DB itself.
2. If not, there are a couple of Java classes for obtaining unique (or near-unique) IDs: java.rmi.server.UID and java.util.UUID. I suggest you also look at them before ploughing ahead too soon.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
prashant chindhade, you should provide the hint to the logic and let others try to figure out the logic. So, don't provide the full implementations

is it ok?

I have always used

or DatabaseConnection is a separate class created by you?


1. If this ID is related to a database table, then I would strongly urge you to use a sequence number obtained from the DB itself

I agree with Winston Gutkowski


kunal
Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
@Kunal and @Winston: Actually i didn't notice the error at first.
but next time i will take care of everything.
thanks for noticing my error.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

prashant chindhade wrote:...but next time i will take care of everything...

As I said before: next time, provide help, not code.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Automatically Generating ID