连接Oracle数据库插入数据却总是报错,非常苦恼,求大侠解释
报错: 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;