This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Automatically Generating ID

 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello All,

i want to generate RegistrationID in the Registration form.

how to do this?
 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put this is Regestration servlet. and call it when you want to get id.

 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose this is my code for Complaint Registration, then where should i put that code.



 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, after running the same code.

Getting an error.

 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohini Dhanaskar wrote:Sir, after running the same code.

Getting an error.



write throw ServletException after destroy method.
 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still showing an compile time error.
 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, Should i make any change in the coding also or what?
 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes,Sir
 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this.

 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which database are you using?
 
Mohini Dhanaskar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, Oracle
 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this Link

it will show you basic steps to connect to database. read full article and than start development.
 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also check this.
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prashant chindhade wrote:...but next time i will take care of everything...

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

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic