| Author |
MAX ID
|
avijit majumder
Greenhorn
Joined: Sep 01, 2009
Posts: 15
|
|
I want to create id .
My code is ....
public static String getID()
{
try{
String qr="select max(id) from user where id like 'EMS%'";
Connection con....
Ststement st....
rs=st.executeQuery(qr);
while(rs.next()){
if(rs.getString(1)=="" ||rs.getString(1)==null)
{total_id="EMS0000";
return total_id;
}
else
{
id=id.substring(3,4);
total_id="EMS"+(Integer.parseInt(id)+1);
return total_id;
}
}//while
}catch(E.....){}
return total_id;
}//end function
NOTE:----
IN DATA BASE id= EMS0009,EMS0010......THEN MAX(ID) Return EMS0009.......
I want to EMS0010.......PL z HELP ME .
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26499
|
|
What database are you using?
I tried the following in postgreSQL and got EMS0010 returned. It's using an alphabetic sort rather than a numeric one, but that's ok if you always have the same number of digits. (leading zeros)
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
Please put your code in a code block so it is easier to read.
I suspect you are getting the wrong ID back because of alphabetic sorting (9 is greater than 10) As Jeanne said, can you double-check to make sure
your data isn't like this:
EMS009
EMS0010
instead of:
EMS0009
EMS0010
|
 |
 |
|
|
subject: MAX ID
|
|
|