' java.sql.SQLException:列类型无效' - 插入数据库时

时间:2017-10-10 12:54:08

标签: java spring oracle11g mybatis

我试图通过在spring框架上构建应用程序将一行插入数据库,并使用mybatis进行数据库处理。我的表看起来像这样:

create table EPAY_OWNER.EPAY_CUSTOMERS
(
  customer_id                NUMBER(19) not null,
  customer_nbr               VARCHAR2(20),
  customer_first_name        VARCHAR2(50),
  customer_last_name         VARCHAR2(50),
  customer_address_1         VARCHAR2(100),
  customer_address_2         VARCHAR2(100),
  customer_state_or_province VARCHAR2(2),
  customer_postal_code       VARCHAR2(9),
  customer_phone             VARCHAR2(15),
  customer_fax               VARCHAR2(15),
  customer_email             VARCHAR2(100),
  customer_city              VARCHAR2(50),
  customer_country           VARCHAR2(25),
  created_by_userid          VARCHAR2(9),
  created_date               TIMESTAMP(6),
  epay_merchant_id           NUMBER(19)
)

CUSTOMER_ID是主键,EPAY_MERCHANT_ID是外键。除主键外,所有字段都可以为空 我的mybatis映射器xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="com.ge.epay.web.dao.EpayCustomerDAO">

    <!-- Inserting a new customer -->
    <insert id="insertCustomer" parameterType="com.ge.epay.web.models.EpayCustomerModel">
        <selectKey keyProperty="customerId" order="BEFORE" resultType="java.lang.Long">
            SELECT EPAY_OWNER.EPAY_CUSTOMER_SEQ.NEXTVAL FROM DUAL
        </selectKey>
        INSERT INTO EPAY_OWNER.EPAY_CUSTOMERS
            (CUSTOMER_ID, CUSTOMER_NBR, CUSTOMER_FIRST_NAME, CUSTOMER_LAST_NAME, CUSTOMER_ADDRESS_1, CUSTOMER_ADDRESS_2,
            CUSTOMER_STATE_OR_PROVINCE, CUSTOMER_POSTAL_CODE, CUSTOMER_PHONE, CUSTOMER_FAX, CUSTOMER_EMAIL, CUSTOMER_CITY,
            CUSTOMER_COUNTRY, CREATED_BY_USERID, CREATED_DATE, EPAY_MERCHANT_ID)
        VALUES
            (#{customerId}, #{customerNbr}, #{firstName}, #{lastName}, #{custAddr1}, #{custAddr2}, #{custState}, #{custZip},
            #{custPhone}, #{custFax}, #{custEmail}, #{custCity}, #{custCountry}, #{createdBy}, SYSTIMESTAMP, #{merchantId})
    </insert>
</mapper>

模型EpayCustomerModel是:

    private long customerId;
    private String customerNbr;
    private String firstName;
    private String lastName;
    private String custAddr1;
    private String custAddr2;
    private String custCity;
    private String custState;
    private String custCountry;
    private String custZip;
    private String custPhone;
    private String custFax;
    private String custEmail;
    private String createdBy;
    private String createdDate;
    private int merchantId;

我想要插入的值是:

EpayCustomerModel [customerId=0, customerNbr=10254, firstName=Test, lastName=Customer, custAddr1=Address 1, custAddr2=Address 2, custCity=Some, custState=FL, custCountry=null, custZip=45986, custPhone=null, custFax=null, custEmail=null.null@ge.com, createdBy=990027140, createdDate=null, merchantId=7]

抛出无效的列类型异常:

java.sql.SQLException: Invalid column type
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3433)
at oracle.jdbc.driver.OraclePreparedStatement.setNullCritical(OraclePreparedStatement.java:4261)
at oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:4250)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:15)
at org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:73)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:61)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:43)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:56)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:28)


难道我做错了什么?我完全陷入困境。任何帮助将不胜感激。

0 个答案:

没有答案