报错: OracleImpl-1:ORA-01858: 在要求输入数字处找到非数字字符实体类代码如下:
package cn.jdbc.tax.entity;
import java.io.Serializable;/**
 * 汽车购置税类
 * @author Administrator
 *
 */
public class VehiclePurchaseTax implements java.io.Serializable{ private static final long serialVersionUID=2070056025956126480L;
//个人身份证
private String id;
public void setID(String ID){
this.id=ID;
}
public String getID(){
return id;
}

//车辆识别代码
private String carNum;
public void setCarNum(String CarNum){
this.carNum=CarNum;
}
public String getCarNum(){
return carNum;
}

//购车日期
private String buyTime;
public void setBuyTime(String BuyTime){
this.buyTime=BuyTime;
}
public String getBuyTime(){
return buyTime;
}

//车型
private float carType;
public void setCarType(float CarType){
this.carType=CarType;

}
public float getCarType(){
return carType;
}

//官方指导价
private int officePrice;
public void setOfficePrice(int OfficePrice){
this.officePrice=OfficePrice;
}
public int getOfficePrice(){
return officePrice;
}

//发票价格
private int ticketPrice;
public void setTicketPrice(int TicketPrice){
this.ticketPrice=TicketPrice;
}
public int getTicketPrice(){
return ticketPrice;
}

//车辆购置税
private int tax;
public void setTax(int Tax){
this.tax=Tax;
}
public int getTax(){
return tax;
}

//构造方法
public VehiclePurchaseTax(){};

public VehiclePurchaseTax(String ID,String CarNum,String BuyTime,float CarType,int OfficePrice,int TicketPrice,int Tax){
this.id=ID;
this.carNum=CarNum;
this.buyTime=BuyTime;
this.carType=CarType;
this.officePrice=OfficePrice;
this.ticketPrice=TicketPrice;
this.tax=Tax;
}
业务实现类代码如下:
package cn.jdbc.tax.dao.impl;
import cn.jdbc.tax.dao.VehiclePurchaseTaxDao;
import cn.jdbc.tax.dao.BaseDao;
import cn.jdbc.tax.entity.VehiclePurchaseTax;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.apache.log4j.Logger;/**
 * 实现接口中save()方法
 * @author Administrator
 *
 */
public class VehiclePurchaseTaxOracleImpl extends BaseDao implements VehiclePurchaseTaxDao{ public static Logger logger=Logger.getLogger(VehiclePurchaseTaxOracleImpl.class.getName());

//定义连接器和执行器
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;

//重写save()方法
public void Save(VehiclePurchaseTax item){
try{
//获取连接
con=BaseDao.getConnection();
//定义SQL语句
String sql="insert into myTax(id,carNum,buyDate,carType,office_price,ticket_price,tax) values(?,?,sysdate,?,?,?,?)";
//加载SQL语句
pstmt=con.prepareStatement(sql);
pstmt.setString(1, item.getID());
pstmt.setString(2, item.getCarNum());
pstmt.setFloat(3, item.getCarType());
pstmt.setInt(4, item.getOfficePrice());
pstmt.setInt(5, item.getTicketPrice());
pstmt.setInt(6,item.getTax());
//执行SQL语句
pstmt.execute();
System.out.println("数据保存成功,车辆购置税为"+item.getTax());

}catch(SQLException e){
System.out.println("数据保存失败!");
logger.error("OracleImpl-1:"+e.getMessage());
}catch(Exception e){
logger.error("OracleImpl-2:"+e.getMessage());
}finally{
//关闭所有数据连接
BaseDao.CloseAll(con, pstmt, rs);
}
}
}界面操作类代码如下:
package cn.jdbc.tax.operation;
import cn.jdbc.tax.entity.VehiclePurchaseTax;
import cn.jdbc.tax.dao.impl.VehiclePurchaseTaxOracleImpl;
import java.util.Scanner;
import org.apache.log4j.Logger;
import java.util.Date;
import java.text.SimpleDateFormat;/**
 * 主界面
 * @author Administrator
 *
 */
public class VehicalPurchaseTaxOperation { public static Logger logger=Logger.getLogger(VehicalPurchaseTaxOperation.class.getName());
//主界面
public void MainView(){
try{
    Scanner input=new Scanner(System.in);
    VehiclePurchaseTax item=new VehiclePurchaseTax();
    System.out.println("记录车辆购置税,请按提示录入相关信息:");
    //输入身份证号码
    System.out.print("请输入车主身份证号码(18位):");
    item.setID(input.next());
    while(item.getID().length()!=18){
    System.out.println("\n身份证号码不足18位!");
    System.out.print("请重新输入:");
    item.setID(input.next());
    }
    //输入车辆识别码
    System.out.print("请输入车辆识别码(17位):");
    item.setCarNum(input.next());
    while(item.getCarNum().length()!=17){
     System.out.println("\n车辆识别码不足17位!");
     System.out.print("请重新输入:");
     item.setCarNum(input.next());
    }
    //输入车辆排量
    System.out.print("请输入车辆排量:");
    item.setCarType(input.nextFloat());
    //输入官方指导价
    System.out.print("请输入官方指导价:");
    item.setOfficePrice(input.nextInt());
    //输入发票价格
    System.out.print("请输入发票价格:");
    item.setTicketPrice(input.nextInt());
    //计算车辆购置税价格
    if(item.getCarType()<=1.6){
     int mon=(int)(item.getTicketPrice()*0.075);
     item.setTax(mon);
    }else{
     int mon=(int)(item.getTicketPrice()*0.1);
     item.setTax(mon);
    }
    //记录车辆购置时间
    Date date=new Date();
    SimpleDateFormat df=new SimpleDateFormat("YYYYMMDD");
    item.setBuyTime(df.format(date).toString());
    System.out.println(item.getID()+"@"+item.getCarNum()+"@"+item.getBuyTime()+"@"+item.getCarType()+"@"+item.getOfficePrice()+"@"+item.getTicketPrice()+"@"+item.getTax());
    //调用VehiclePurchaseTaxOracleImpl的save方法
    VehiclePurchaseTaxOracleImpl impl=new VehiclePurchaseTaxOracleImpl();
    impl.Save(item);
}catch(Exception e){
logger.error("Operation-1:"+e.getMessage());
}
}
}

解决方案 »

  1.   

    补充:数据库表中各元素的数据类型
    id char(18);
    carNum char(17);
    buyDate date;
    carType number(11,1);
    office_price number(11);
    ticket_price number(11);
    tax number(11);
    并且Sql语句中各参数的位置排列正确
      

  2.   

    运行过程:
    记录车辆购置税,请按提示录入相关信息:
    请输入车主身份证号码(18位):310225198802065562
    请输入车辆识别码(17位):12345678912345678
    请输入车辆排量:1.8
    请输入官方指导价:220000
    请输入发票价格:200000
    310225198802065562@12345678912345678@[email protected]@220000@200000@20000
    数据保存失败!
    ERROR - OracleImpl-1:ORA-01858: 在要求输入数字处找到非数字字符
      

  3.   

    实体类中对应元素类型
    id String
    carNum String
    buyTime String
    carType float
    officePrice int
    ticketPrice int
    tax int 
      

  4.   

    首先依次检查每一项的数据pstmt.setString(1, item.getID());
    pstmt.setString(2, item.getCarNum());
    pstmt.setFloat(3, item.getCarType());
    pstmt.setInt(4, item.getOfficePrice());
    pstmt.setInt(5, item.getTicketPrice());
    pstmt.setInt(6,item.getTax());主要看看这item中取出来的值。
    如果值都是正确的,建议你对表中的所有列一个一个的insert测试一下,看看到底是哪一列导致的错误。
      

  5.   

    是不是日期问题
    buyDate date和buyTime String
      

  6.   

    会不会是carType属性录入值的时候,录入的数据超过了float的表示范围,程序自动转成了科学计数法形式而导致的问题呢?