Samuel Learning

  • 联系
  •  
  • 管理

文章分类(203)

  • 01 ASP/HTML(6)
  • 02 Script/CSS(16)
  • 03 C/C++
  • 04 XML(4)
  • 05 微软编程(26)
  • 06 J2EE(60)
  • 09 Linux(14)
  • 10 Database(27)
  • 11 报表打印
  • 12 打包安装(1)
  • 13 模式重构(2)
  • 14 系统架构
  • 15 敏捷开发(11)
  • 16 案例分析(30)
  • 17 Workflow(1)
  • 18 配置管理(1)
  • 19 项目管理
  • 20 英语(4)

新闻分类(52)

  • CXF学习
  • Hibernate学习(1)
  • iBatis学习(16)
  • Struts1学习(1)
  • Struts2学习(34)

.NET资源

  • adxmenu
  • C# Open Source
  • DNN Directory
  • M2Land
  • Windows Form FAQ
  • 中国DNN
  • 中国DNN联盟

Ajax

  • DoJo
  • GWT
  • JQuery
  • jquery autocomplete
  • jquery flexgrid
  • JQuery Form
  • jquery masked input
  • JQuery UI
  • jquery validation
  • Jquery 图表
  • jquery报表
  • jquery插件集合
  • Qooxdoo
  • Tibco GI
  • YUI
  • YUI-EXT
  • ZeroKode

Java开源

  • ABLE
  • Agile Tao
  • Ajax4JSF
  • Alfresco
  • AppFuse
  • Compiere
  • Equinox
  • Findbugs
  • Geronimo
  • Grails
  • Harmony
  • Hibernate论坛
  • JAG
  • Java开源大全
  • Java视线论坛
  • jBPM工作流
  • JSFTutorials
  • Nereide ERP
  • Ofbiz ERP
  • Opentaps ERP
  • operamasks
  • Petstore
  • Prototype.js
  • RIFE
  • Runa
  • SpringSide
  • Struts Menu
  • Sun Glassfish
  • Trails
  • YUI4JSF
  • 满江红

Mobile

  • Sencha

WEB资源

  • DHTML中心
  • DHTML参考手册
  • DHTML文档
  • EclipsePlugin
  • Firebug
  • GRO Clinux
  • jMaki
  • JSTL文档
  • LoadIcon
  • Openlaszlo
  • Struts Menu 展示
  • Web Test Tools
  • WebCtrs
  • Webdeveloper
  • 中国RIA开发者论坛

Workflow

  • E-Workflow
  • JBPM
  • OpenWFE
  • OSWorkflow
  • WFMC
  • Workflow Research

其他连接

  • confach
  • CPP
  • ejay
  • Giovanni
  • 丹佛
  • 交大e-learning
  • 交大研究生院
  • 可恶的猫
  • 天天@blog
  • 我的相册
  • 阿飞

大牛人

  • 32篇JBPM
  • David.Turing
  • HongSoft@业务集成
  • Joel
  • Koen Aers
  • Martinfowler
  • Raible Matt
  • Raible Wiki
  • Scott W.Ambler
  • Tom Baeyens
  • Uncle Bob
  • 一个世界在等待
  • 子在川上曰
  • 小布老师
  • 小明
  • 差沙
  • 徐昊
  • 江南白衣
  • 汪博士
  • 汪小金
  • 银狐999

开源软件

  • 2Bizbox ERP
  • CompiereCRM&ERP
  • EGW
  • Vtiger CRM
  • webERP

敏捷

  • Canoo
  • Cruisecontrol
  • DBUnit
  • EL4Ant
  • Extreme Programming
  • Fit
  • Fitnesse
  • JFrog
  • Liquibase
  • Maven
  • MockObjects
  • Selenium
  • Squish
  • xpairtise
  • XPlanner
  • XProgramming
  • 敏捷联盟

数据库

  • Oracle 中国
  • Oracle-ERP
  • Oracle在线社区

未归类

  • Aquarius Orm Studio
  • mambo建站系统
  • Oracle产品下载
  • 远程同步管理工具Capivara

经典框架

  • Apache Shale
  • formdef-struts
  • FreeMarker 主页
  • JBoss Seam
  • JSF 中心
  • JSF 入门应用
  • JSF中国
  • MyFaces官方
  • Spring 社区
  • Spring专业网站
  • Spring中文论坛
  • Spring参考手册
  • Spring官方网站
  • strecks-struts
  • Struts1
  • Struts2
  • Struts-layout
  • StrutsWiKi
  • Tapestry WIKI
  • Tapestry 官方
  • Tapestry4开发指南
  • Tapestry中文文档
  • Webwork2文档
  • Wicket

网络教程

  • Laliluna
  • RoseIndia
  • Sang Shin
  • Visualbuilder

著名站点

  • Buildix
  • Dev2Dev
  • IBM dev中国
  • InfoQ
  • ITPub
  • Java Eye
  • Java Research
  • JavaRead
  • JavaWorldTW
  • Matrix
  • PHP100
  • PHPX
  • SpringSideWiKi
  • TheServerSide
  • TWPHP
  • 中国工作流论坛

项目管理

  • 管理人网

最新评论

View Post

What causes an Invalid column type error with Oracle

This error is a bit misleading. What it is trying to tell you is that your jdbc driver does not know how to set one of your columns to null. In the following section I will show you what causes this error and how to correct it.

First lets start with a simple POJO (Plain Old Java Object).

Address.java
import java.util.Date;
public class Address {
private String line1;
private String line2;
private String city;
private String state;
private String postalCode;
private Date purchaseDate;
private Date soldDate;
...  Standard mutators (getters setters) ...
}

Here is the example table that we will be using.

Address.sql
Address {
line1			varchar2(100),
line2			varchar2(100),
city			varchar2(100),
state			varchar2(100),
postal_code	varchar2(25),
purchase_date	date,
sold_date		date
}

With this in place we can create the sqlmaps to work with it. With this error only your insert and update statements will be of concern. I will use an insert both the solution works for both.

Address.xml
<typeAlias alias="Address" type="com.abc.domain.Address"/>
<insert id="insertAddress" parameterClass="Address">
INSERT INTO
ADDRESS (
line1,
line2,
city,
state,
postal_code,
purchase_date,
sold_date
)
values (
#line1#,
#line2#,
#city#,
#state#,
#postal_code#,
#purchase_date#,
#sold_date#
)
</insert>

So far everything looks good and will work part of the time. In the following example the classic invalid column type error will be thrown.

Example.java
Address address = new Address();
address.setLine1("123 Anywhere Street");
address.setCity("Somewhere over the Rainbow");
address.setState("Never never land");
address.setPostalCode("01234");
address.setPurcahseDate(purcahseDate);  //purchaseDate defined somewhere above this code

Notice in the code above that I leave the line2 and soldDate properties as null. This is where the problem creeps in. When the insert sqlmap come to the line2 column it will throw an error. There are two solutions for this problem.

The first is to use dynamic conditions.

Address.xml
<typeAlias alias="Address" type="com.abc.domain.Address"/>
<insert id="insertAddress" parameterClass="Address">
INSERT INTO
ADDRESS (
line1,
line2,
city,
state,
postal_code,
purchase_date,
sold_date
)
values (
#line1#,
<isNull property="line2">
null,
</isNull>
<isNotNull property="line2">
#line2#,
</isNotNull>
#city#,
#state#,
#postal_code#,
#purchase_date#,
#sold_date#
)
</insert>

As you can see this can become a time consuming process to make sure that every column that can be null has these tags. A second and cleaner option is to define what the jdbc type is.

Address.xml
<typeAlias alias="Address" type="com.abc.domain.Address"/>
<insert id="insertAddress" parameterClass="Address">
INSERT INTO
ADDRESS (
line1,
line2,
city,
state,
postal_code,
purchase_date,
sold_date
)
values (
#line1#,
#line2:VARCHAR#,
#city#,
#state#,
#postal_code#,
#purchase_date#,
#sold_date:DATE#
)
</insert>

Just do this only any column that can be null! Now you may be asking yourself what are the valid jdbc types. Look no further they are posted in the Java API documents java.sql.Types.


主要原因是没有对inline参数制定类型。

posted on 2008-07-23 00:23 MingIsMe 阅读(390) 评论(0)  编辑  收藏 所属分类: iBatis学习

 
Powered by:
BlogJava
Copyright © MingIsMe