java - i/p 字符串错误

标签 java

在我的项目中,我有一个主窗口,其中有更新按钮,但是当我更新数据时,它显示错误,即错误:对于输入字符串:“2345678.0”

//整个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"

我的代码是:

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,"RECORD 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

您正在尝试将可以表示为 doublefloatString 转换为 int。如果字符串不包含可解析的整数,Integer.parseInt() 方法将抛出 java.lang.NumberFormatException

所以

Integer.parseInt(tftele.getText())

应该是

Double.parseDouble(tftele.getText())

Float.parseFloat(tftele.getText())

关于java - i/p 字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5575544/

相关文章:

Java,从嵌套 for 循环生成的单独行中删除重复输出

java - java中的完美数使用方法做作业

java - 删除广告时调整布局大小

java - 如何从字符串变量java的最后一个字符中解脱出来

java - 如何处理 "[ERROR] Exception in thread "main“java.lang.OutOfMemoryError : Java heap space"in JENKINS?

java - 尝试从 SQL 数据库检索数据到 listview android 时收到空指针异常

java - 删除java中URL中斜杠之间的所有字符

java - Android mvvm - 每个 CRUD 操作都应该有自己的 ViewModel 吗?

java - Swagger 与 Play2 集成

java - 使用 m2eclipse 设置多个项目的最佳实践