I have set "phone" as int of 10 digit in database and take input as text which I parse using
String phone1=request.getParameter("phone");
int phone =Integer.parseInt(phone1);
but it does not work why?
In Java you can store in int variable numbers in range -2147483648 to 2147483647. This is not enough for your 10-digit telephone numbers. You can easily fix this using long:
long phone = Long.parseLong(phone1);
On the other hand I would rethink using number data types for storing telephone numbers. Why?
# or p, that are valid and used sometimes in phone numbersIf your phone is in format sth like (+3212-45-356) or sth else. Before you parse it you have to make that string clean from that 'special characters'. Try parsing it to long.
String phone1=request.getParameter("phone");
Long phone =Integer.parseLong(phone1.replace("\\+","").replace.("-",""));
One problem is, that a preceding 0 will make the number, octal, in base 8; and then digits 8 and 9 cause a NumberFormatException. Base 8 allows to represent 3 bits 0-1 with one digit 0-7.
long phone = Long.parseLong(phone1, 10);
This forces base 10.
Of course, as one does not calculate with phone numbers, and by this conversion looses preceding zeroes, this might be less suited. In many countries international numbers are entered with either preceding + or 00.
int parseInt(String s) {return parseInt(s,10);}
301-555-42. And what about reconstructing the string? Leading zeros would be stripped.does not work