
正文
JAVA 中CLOB与Clob有区别
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
在JAVA中CLOB与Clob是有区别的类型。
(oracle.jdbc.internal.OracleCallableStatement)OracleCallableStatement能接收CLOB的数据类型,
(java.sql.CallableStatement)CallableStatement能接收Clob的数据类型。
CODE示例
PACKAGE
CREATE OR REPLACE PACKAGE BODY cux_test_clob_pkg IS
PROCEDURE test_lower_clob(p_parameter_id IN NUMBER,
x_out_xml OUT Clob) IS
l_temp_str VARCHAR2(32767); l_temp_clob CLOB;
BEGIN dbms_lob.createtemporary(x_out_xml,
TRUE);
l_temp_str := '<?xml version="1.0" encoding="GBK"?>' || fnd_global.newline; dbms_lob.writeappend(lob_loc => x_out_xml,
amount => length(l_temp_str),
buffer => l_temp_str); END;PROCEDURE test_upper_clob(p_parameter_id IN NUMBER,
x_out_xml OUT CLOB) IS
l_temp_str VARCHAR2(32767); l_temp_clob CLOB;
BEGIN dbms_lob.createtemporary(x_out_xml,
TRUE);
l_temp_str := '<?xml version="1.0" encoding="GBK"?>' || fnd_global.newline; dbms_lob.writeappend(lob_loc => x_out_xml,
amount => length(l_temp_str),
buffer => l_temp_str); END;END;
//获取CLOB
private Clob getSuppRegXMLClob(OAPageContext pageContext, OAWebBean webBean,String parameterId){
Clob clob = null;
OADBTransaction localOADBTransactionImpl =
(OADBTransaction)pageContext.getApplicationModule(webBean).getOADBTransaction();
OracleCallableStatement localCallableStatement = null;
LogUtil.of("getSuppRegXMLClob mappingId= "+mappingId+" suppCateMappingId="+suppItemCateMappingId,pageContext).print(pageContext);
try { String str =
"begin\n" +
" cux_test_clob_pkg.test_upper_clob(p_parameter_id => :1,\n" +
" x_out_xml => :2);\n" +
"end;";
localCallableStatement = (oracle.jdbc.internal.OracleCallableStatement)localOADBTransactionImpl.createCallableStatement(str, 1);
localCallableStatement.setObject(1, mappingId);
localCallableStatement.registerOutParameter(2, OracleTypes.CLOB);
localCallableStatement.execute();
clob = localCallableStatement.getCLOB(2);
localCallableStatement.close();
} catch (SQLException localException2) {
clob = null;throw new OAException("getSuppRegXMLClob cux_test_clob_pkg.test_lower_cloberror!"+localException2.getMessage());
} finally {
try {
if (localCallableStatement != null)
localCallableStatement.close();
} catch (Exception localException4) {
throw new OAException("getSuppRegXMLClob error!");
} } return clob;
}
//获取Clob
private CLOB getSuppRegXMLClob(OAPageContext pageContext, OAWebBean webBean,String parameterId){
CLOB clob = null;
OADBTransaction localOADBTransactionImpl =
(OADBTransaction)pageContext.getApplicationModule(webBean).getOADBTransaction();
CallableStatement localCallableStatement = null;
LogUtil.of("getSuppRegXMLClob mappingId= "+mappingId+" suppCateMappingId="+suppItemCateMappingId,pageContext).print(pageContext);
try { String str =
"begin\n" +
" cux_test_clob_pkg.test_upper_clob(p_parameter_id => :1,\n" +
" x_out_xml => :2);\n" +
"end;";
localCallableStatement = localOADBTransactionImpl.createCallableStatement(str, 1);
localCallableStatement.setObject(1, mappingId);
localCallableStatement.registerOutParameter(2, OracleTypes.CLOB);
localCallableStatement.execute();
clob = localCallableStatement.getClob(2);
localCallableStatement.close(); } catch (SQLException localException2) {
clob = null;
throw new OAException("getSuppRegXMLClob cux_test_clob_pkg.test_upper_clob!"+localException2.getMessage());
} finally {
try {
if (localCallableStatement != null)
localCallableStatement.close();
} catch (Exception localException4) {
throw new OAException("getSuppRegXMLClob error!");
} } return clob;
}








