i have created a jsp page displaying a form that have a field Booking ID, that should be an unique field(PK) in the BookingDetails table.
Now i want to generate a number that get displayed in the Booking ID text automatically and increase by 1 on every time the page is called, i.e., first time the Booking Id will be say 001, then 2nd time 002 and so on.....
I have written a class for that (which is not working)..
it is displaying "B00-9999" each time.
how could i get the number starting from 0001 and increment it on every page call. I don't have any idea.
Some one help please..
Each time your page is hit, the method is called and it generates the same number, so what you need is to always get a newly generated id. Better to say you probably need to get it from your underlying database. For e.g in oracle you can use sequence. Other databases might be having some different ways.
No i am not getting any exception, i was just asking that.
I am trying to fetch the last ID from the database and increment it by 1. then store it in database as the next id.
Don't know whether it'll work, let's see.
ok, tell me, is it possible to fetch the last Booking id? I have set the Booking_ID field as hierarchyid type in sql database.
Now, if i auto increment the id field that means i dont have to insert that field from within a jsp, since it is automatically inserted, right? Or is it that i have to insert it manually?
I am trying to fetch the last ID from the database and increment it by 1. then store it in database as the next id. autoincrement (in primary key, please see my earlier post) means when a new record is inserted, it will automatically incremented by one (also you set the increment by your desire sequence).
so for your "Booking_ID" will automatically incremented you don't have to insert it manually.
subject: how to automatically generate a sequence of numbers