开发者

Error in i/p string

In my project I have main window in which I have taken update button but when I am updating the data its showing error i.e error: For input string: "2345678.0"

//entire o/p

init:
Deleting: C:\Documents and Settings\amit bidwai\sanskar1\build\built-jar.properties
deps-jar:
Updating property file: C:\Documents and Settings\amit bidwai\sanskar1\build\built-jar.properties
compile:
run:

 Driver loaded
Hi
SeniorPerson: cvbxc
RegistrationNo: 7
NativePlace: bvb
Kul: bvb
Gotra: bvb
KulSwami: bv
ResidensialAddress: fdgd
PinCode: 6564
STDcode: null
TelephoneNo: 5435435.0
MobileNo: 5435435
Email: fdsfsd@
Website: hgfhgfh
Education: hgfh
Branch: hgfh
BloodGroup: A+ve

 Driver loaded
Hi
SeniorPerson: arya
RegistrationNo: 25
NativePlace: hgh
Kul: hgh
Gotra: hgh
KulSwami: hgh
ResidensialAddress: hghg
PinCode: 2344356
STDcode: 4343
TelephoneNo: 2345678.0
MobileNo: 1234567891
Email: dsa@
Website: www
Education: hgfhh
Branch: ghfh
BloodGroup: O-ve

 Driver loaded
statement is created
error:For input string: "2345678.0"

my code is:

String regno1= cbregn.getSelectedItem().toString();
          if(regno1.equals("")){
          JOptionPane.showMessageDialog(null," ENTER THE REGISTRATION NO ");
 return;
        }

         try
         {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          System.out.println("\n Driver loaded");
          Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
          Statement stmt=con.createStatement();
          System.out.println("statement is created");

          String qry= " UPDATE Registration1 set RegistrationNo = '"+cbregn.getSelectedItem().toString()+"',SeniorPerson = '"+cbnm.getSelectedItem().toString()+"', NativePlace = '"+tfplace.getText()+"', Kul = '"+tfkul.getText()+"', Gotra = '"+tfgotra.getText()+"' ,KulSwami = '"+tfswami.getText()+"', ResidensialAddress = '"+taraddr.getText()+"' , PinCode = '"+Integer.parseInt(tfpcd.getText())+"', STDcode = '"+Integer.parseInt(tfstdcode.getText())+"', TelephoneNo = '"+Integer.parseInt(tftele.getText())+"', MobileNo = '"+Integer.parseInt(tfmno.getText())+"', Email = '"+tfemail.getText()+"',Website ='"+tfweb.getText()+"',Education ='"+tfedu.getText()+"',Branch ='"+tfbrch.getText()+"',BloodGroup ='"+cbbldgrp.getSelectedItem().toString()+"' where RegistrationNo='" +Integer.parseInt(cbregn.getSelectedItem().toString())+"'" ;
          String qry1= " UPDATE Registration1 set RegistrationNo = '"+cbregn.getSelectedItem().toString()+"',SeniorPerson = '"+cbnm.getSelectedItem().toString()+"', NativePlace = '"+tfplace.getText()+"', Kul = '"+tfkul.getText()+"', Gotra = '"+tfgotra.getText()+"' ,KulSwami = '"+tfswami.getText()+"', ResidensialAddress = '"+taraddr.getText()+"' , PinCode = '"+Integer.parseInt(tfpcd.getText())+"', STDcode = '"+Integer.parseInt(tfstdcode.getText())+"', TelephoneNo = '"+Integer.parseInt(tftele.getText())+"', MobileNo = '"+Integer.parseInt(tfmno.getText())+"', Email = '"+tfemail.getText()+"',Website ='"+tfweb.getText()+"',Education ='"+tfedu.getText()+"',Branch ='"+tfbrch.getText()+"',BloodGroup ='"+cbbldgrp.getSelectedItem().toString()+"' where SeniorPerson='" +cbnm.getSelectedItem().toString()+"'" ;
          stmt.executeUpdate(qry);
          stmt.executeUpdate(qry1);
          JOptionPane.showMessageDialog(null,"RECO开发者_如何学CRD IS UPDATED SUCCESSFULLY ");
          System.out.println("QUERY");       

          cbregn.setEditable(false);
          cbnm.setEditable(false);
          tfplace.setEditable(false);
          tfkul.setEditable(false);
          tfgotra.setEditable(false);
          tfswami.setEditable(false);
          taraddr.setEditable(false);
          tfpcd.setEditable(false);
          tfstdcode.setEditable(false);
          tftele.setEditable(false);
          tfmno.setEditable(false);
          tfemail.setEditable(false);
          tfweb.setEditable(false);
          tfedu.setEditable(false);
          tfbrch.setEditable(false);
          cbbldgrp.setEditable(false);
          con.close();
          stmt.close();
        }
        catch(SQLException eM)
        {
        JOptionPane.showMessageDialog(null,"RECORD IS NOT FOUND ");
        }
        catch(Exception et)
        {
        System.out.println("error:"+et.getMessage());
        }  


TelephoneNo: 5435435.0
TelephoneNo: 2345678.0

You are trying to convert the String that can be represented as double or float to int. If the string does not contain a parsable integer, Integer.parseInt() method throws java.lang.NumberFormatException.

so

Integer.parseInt(tftele.getText())

should be

Double.parseDouble(tftele.getText())

or

Float.parseFloat(tftele.getText())


As the details you have given the problem is looking inside date that you are passing. As your code is demanding for mobile number/phone number it is never being a float or double type. It should be of type int or long as your requirement.

error:For input string: "2345678.0"

pass this data without decimal point then your code should work. In other case if you wanted to handle this kind of situation then your two solutions

  1. Just remove the numbers after decimal from mobile number by using string method and then convert it into integer data type.
  2. If you don't want this then convert the passed string into float/double type then type cast into int type.

For reference of type conversion and casting reffer this http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜