我的代码在保存数据时发出错误。错误即将发生在DATE我已将此DATE的数据类型作为日期/时间以ms访问DB.i也给出了我的代码,错误如下
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "4.5.5255"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:456)
at java.lang.Integer.parseInt(Integer.java:497)
at sanskarwani.saveREGISTRATION1(sanskarwani.java:3667)
at sanskarwani.access$800(sanskarwani.java:31)
at sanskarwani$9.actionPerformed(sanskarwani.java:1224)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
我的代码是:
int len,len1,len2;
int regno= Integer.parseInt(cbregn.getSelectedItem().toString());
if(cbregn.getSelectedItem().toString().equals("")){
JOptionPane.showMessageDialog(null," SELECT THE REGISTRATION NO ");
return;
}
int dt=Integer.parseInt(tdate.getText());
if(tdate.getText().equals(""))
JOptionPane.showMessageDialog(null," ENTER THE DATE ");
// String date=tdate.getText();
// if(date.equals(""))
// JOptionPane.showMessageDialog(null," ENTER THE DATE ");
String nm= cbnm.getSelectedItem().toString();
if(nm.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE NAME ");
return;
}
String place=tfplace.getText();
if(place.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE NATIVE PLACE ");
return;
}
String kul=tfkul.getText();
if(kul.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE NAME OF KUL ");
return;
}
String gotra=tfgotra.getText();
if(gotra.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE GOTRA NAME ");
return;
}
String kswami=tfswami.getText();
if(kswami.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE KULSWAMI NAME ");
return;
}
String raddr=taraddr.getText();
if(raddr.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE RESIDENSIAL ADDRESS ");
return;
}
int pincode=Integer.parseInt(tfpcd.getText());
len1 = tfpcd.getText().length();
if(len1!=7) {
JOptionPane.showMessageDialog(null,"Enter The 7 Digit Pin Code","Error",JOptionPane.ERROR_MESSAGE);
return;
}
int stdcd=Integer.parseInt(tfstdcode.getText());
if(tfstdcode.getText().equals("")){
JOptionPane.showMessageDialog(null," ENTER THE STD CODE ");
return;
}
int tele=Integer.parseInt(tftele.getText());
len2 = tftele.getText().length();
if(len2!=7){
JOptionPane.showMessageDialog(null,"Enter The 7 Digit Telephone No","Error",JOptionPane.ERROR_MESSAGE);
return;
}
int mno=(int) Long.parseLong(tfmno.getText());
len = tfmno.getText().length();
if(len!=10) {
JOptionPane.showMessageDialog(null,"Enter The 10 Digit Mobile No","Error",JOptionPane.ERROR_MESSAGE);
return;
}
String email=tfemail.getText();
if(email.equals(""))
JOptionPane.showMessageDialog(null," ENTER THE EMAIL");
if(email.equals("")) {
tfemail.setText("-");
} else // check if it is a valid email-id
{
int ind = email.indexOf("@");
if (ind != -1) { } else {
JOptionPane.showMessageDialog(null,"Invalid Email Id","Error",JOptionPane.ERROR_MESSAGE);
tfemail.setText("");
tfemail.requestFocus();
return;
}
}
String website=tfweb.getText();
if(website.equals(""))
JOptionPane.showMessageDialog(null," ENTER THE WEBSITE ");
if(website.equals("")) {
tfweb.setText("-");
}
else // check if it is a valid email-id
{
int ind = website.indexOf("www");
if (ind != -1) { } else {
JOptionPane.showMessageDialog(null,"Invalid Website","Error",JOptionPane.ERROR_MESSAGE);
tfweb.setText("");
tfweb.requestFocus();
return;
}
}
String education=tfedu.getText();
if(education.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE EDUCATION DETAILS");
return;
}
String branch=tfbrch.getText();
if(branch.equals("")){
JOptionPane.showMessageDialog(null," ENTER THE BRANCH NAME ");
return;
}
int bdt=Integer.parseInt(tfbdt.getText());
if(tfbdt.getText().equals(""))
// String brthdt=tfbdt.getText();
// if(brthdt.equals(""))
JOptionPane.showMessageDialog(null," ENTER THE BIRTH DATE");
String bloodgrp=(String)cbbldgrp.getSelectedItem();
if(bloodgrp.equals("")){
JOptionPane.showMessageDialog(null," SELECT THE BLOODGROUP");
return;
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
Statement stmt=con.createStatement();
String qry= "INSERT INTO Registration1(RegistrationNo,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BloodGroup,Date,BirthDate) VALUES('"+regno+"','"+nm+"','"+place+"','"+kul+"','"+gotra+"','"+kswami+"','"+raddr+"','"+pincode+"','"+stdcd+"','"+tele+"','"+mno+"','"+email+"','"+website+"','"+education+"','"+branch+"','"+bloodgrp+"','"+dt+"','"+bdt+"')";
// System.out.println("qry");
// String qry= "INSERT INTO Registration1(RegistrationNo,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BloodGroup,Date,BirthDate) VALUES('"+regno+"','"+nm+"','"+place+"','"+kul+"','"+gotra+"','"+kswami+"','"+raddr+"','"+pincode+"','"+stdcd+"','"+tele+"','"+mno+"','"+email+"','"+website+"','"+education+"','"+branch+"','"+bloodgrp+"','"+dt+"','"+bdt+"')";
stmt.executeUpdate(qry);
JOptionPane.showMessageDialog(null,"RECORD IS SAVED SUCCESSFULLY ");
con.close();
}
catch(SQLException eM) {
System.out.println(" "+eM);
JOptionPane.showMessageDialog(null,"RECORD IS NOT SAVED");
}
catch(Exception et)
{
System.out.println("error:"+et.getMessage());
}
答案 0 :(得分:2)
您正在尝试将包含浮点的字符串格式的十进制格式化为整数。
int类型不应该有浮点。
您可以将此字符串转换为整数:
455255
但这不是一个正确的整数:
4.5.5255
试试这个:
string number = "4.5.5255";
number = number.replace(".", "");
Integer.parseInt(number );
答案 1 :(得分:2)
你的执行中的第一行:
异常 在线程“AWT-EventQueue-0” java.lang.NumberFormatException:For 输入字符串:“4.5.5255”
这意味着您正在尝试解析不是数字的4.5.5255。
很难说你的代码在哪一行得到了这个例外。[可能在sanskarwani.java:3667
]。我的意思是在您发布的代码中我们如何找到行号3667.尝试调试代码并分别发布错误的代码。