0

I want to insert mobile no. of users at the time of registration and I have already expand the length of integer to 255 but I am getting this exception. Can anyone please solve this problem?

  com.mysql.jdbc.MysqlDataTruncation: Data truncation:
    Out of range value adjusted for column 'mobno' at row 1
Mat
  • 202,337
  • 40
  • 393
  • 406
Roopam
  • 270
  • 2
  • 12
  • 1
    Phone numbers should be stored as *strings* (varchar) not as an integer type. – Alex K. May 16 '15 at 16:18
  • but why integer is not applicable?? – Roopam May 16 '15 at 16:20
  • but i am not using + and 0 – Roopam May 16 '15 at 16:23
  • Phone numbers are not numbers in a mathematical sense, think of them like words with their own alphabet (with letters 0-9, +, # etc.). – Josef Engelfrost May 16 '15 at 16:27
  • would you plz explain in detail.... I am unable to get it exactly what are you trying to tell? – Roopam May 16 '15 at 16:29
  • We are saying store them as strings - as a series of digits - not as an integer representation of the phone number as a number – Alex K. May 16 '15 at 16:30
  • Yaa i got it but i am trying to understand the reason behind it.. – Roopam May 16 '15 at 16:31
  • 1
    See [What's the right way to represent phone numbers?](http://stackoverflow.com/questions/3483156/whats-the-right-way-to-represent-phone-numbers) – Alex K. May 16 '15 at 16:33
  • Even you use int(255) , it will not store 255 byte integers for your. Try convert to a varchar or char(12). see http://stackoverflow.com/questions/7171312/what-is-the-max-number-if-i-store-int255-in-mysql. Also your jdbc driver will not be able to handle a 255-byte integer. – Tim3880 May 16 '15 at 16:34
  • if you are **not doing math operations** on something it is **not a number** regardless of if it is comprised of only digits –  May 16 '15 at 18:35

1 Answers1

0

Everything in the digital world is a number. It's not that that you can't do this. It's that doing it makes things pointlessly difficult.

Aside from the + and leading 0 issues, which should not be casually dismissed, the two primary operations performed on phone numbers are validating and presenting them to the user in a standard format. Both of these are easier to do with strings. Even if you make this work with a number all you gain is a micro compression of data at the expense of readable code.

varchar is how you do this in mySQL. It won't require that you know the length of the phone number ahead of time.

Also note that the same phone number exists in different forms from different perspectives. In some places the country code or the area code can be left off. Ask for these in separate fields and the input will be more universally useful.

Formatting information (), -, ., etc, should ether be standardized or stripped out when stored and reapplied when displayed to ensure that storage is independent of presentation.

While you claim that you are not using + and leading 0 now please consider how difficult a numeric based design would make adding them in the future.

See MySQL - how to store phone numbers?

Community
  • 1
  • 1
candied_orange
  • 7,036
  • 2
  • 28
  • 62