By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

Storing in mysql JFormattedField

P: 9
I have a jFormatted Field name "txtContact" in my Java Swing and I put an input mask ###-###-##### ex. 123-456-78910 what I want is to save this in MySQL database without the dash "-" ex: 023-456-78901 will be save 02345678901 (i want that the first digit zero will also be included). Can someone help me?

I tried this code

Expand|Select|Wrap|Line Numbers
  1. String str = this.txtContact.getText();
  2. NumberFormat f = NumberFormat.getInstance(); 
  3. long contact = f.parse(str).longValue();
and if I enter 090-512-34567
it stores only "90" how am I going to get all the numbers I enter eliminating the dash (-) and including zero(0). Thank you for your help.
Feb 18 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,422
Don't parse it as a number, that will drop the leading zeroes. Instead, use a replace function to remove the dashes before inserting.
Feb 18 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.