最近在做OAF(Oracle Application Framework)项目的时候,发现一个问题,如果一个字段大于2000,在数据库插入的时候不会有问题,如果在页面插入(大于2000但没有超过这个字段的长度),OAF页面自带的验证不会报错,但是一提交到数据库就会报字符过长的问题。一般情况下,我们普通的SQL以“select、update”开头的SQL,在提交的时候会调 PreparedStatement这个接口的ps.setString()方法,这个方法对字符的的限制为2000,所以会有问题,如果是CallableStatement就没问题,给出一种解决方法,在EO里面重写buildDMLStatement方法,即,加上下面一段代码:
这样就会调CallableStatement这个接口。
protected StringBuffer buildDMLStatement(int operation,
AttributeDefImpl[] allAttrs,
AttributeDefImpl[] retCols,
AttributeDefImpl[] retKeys,
boolean batchMode)
{
StringBuffer result = super.buildDMLStatement(operation, allAttrs, retCols, retKeys, batchMode);
result.insert(0, "BEGIN ");
result.append("; END;");
return result;
}
这样就会调CallableStatement这个接口。