我正在构建一个Web服务,它在有效负载中获取输入XML并将其存储在数据库中。
在DAO层中,我使用XML String创建一个clob对象,如:
CLOB clob = CLOB.createTemporary(conn,false,CLOB.MODE_READWRITE);
clob.putString(1,inputXml);
我将此clob对象传递给存储过程:
declareParameter(new SqlParameter("i_xml", OracleTypes.CLOB));
并在可执行方法中:
params.put("i_xml",clob);
Map<?, ?> result = execute(params);
所以,当我调用这个Web服务时,我可以看到XML正在被正确地发送到Oracle DB,但是我收到来自数据库的错误说:
System Error occured while Creating ORA-22922: nonexistent LOB value
请告诉我如何解决此问题。提前谢谢。
答案 0 :(得分:0)
准备好的语句应该是OracleCallableStatement类型,然后按照下面的示例代码进行操作
stmt = (OracleCallableStatement) conn.prepareCall("{call MSG(" + repeatQmarks(7) + ")}");
stmt.setBigDecimal("P_W_EVENT_LOG_KEY", wEventLogKey); //1 P_W_EVENT_LOG_KEY IN NUMBER,
stmt.setString("P_DOMAIN", domain); //2 P_DOMAIN IN VARCHAR2,
stmt.setString("P_EXCPT_CD", sqlExCd); //3 P_EXCPT_CD IN VARCHAR2,
stmt.setString("P_EXCPT_MSG", sqlExMsg); //4 P_EXCPT_MSG IN VARCHAR2,
stmt.setStringForClob("P_PAYLOAD_IN", "My TEST CLOB 1"); //5 P_PAYLOAD_IN IN CLOB DEFAULT NULL,
stmt.setStringForClob("P_PAYLOAD_OUT", "My TEST CLOB 2"); //6 P_PAYLOAD_OUT IN CLOB DEFAULT NULL,
stmt.registerOutParameter("P_RET_CD", java.sql.Types.NUMERIC); //7 P_RET_CD OUT NUMBER);
注意方法
,第5和第6个参数实际上是字符串setStringForClob