在我的项目中,我有一个主窗口,其中有更新按钮,但是当我更新数据时,它显示错误,即错误:对于输入字符串:“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
您正在尝试将可以表示为 double
或 float
的 String
转换为 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/