嗨,我是使用这项技术(Oracle SP)的新手,所以我遇到了一些问题,
具体来说,我想在存储过程中插入一个 BLOB 对象,目前我使用的是 spring、jboss、java 和 oracle,我的 SP 比:
PROCEDURE SAVE_DATA(data IN BLOB, date IN DATE) IS
next_id number;
BEGIN
select s_id.nextval into next_id from dual;
INSERT INTO DATA_TABLE( id, data , date)
values
(next_id, data , date);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20101,''||SQLCODE ||'-'||SUBSTR(SQLERRM,1,500));
END SAVE_FAILED_EMAIL;
所以在java方面,我做这样的事情:
WrappedConnection wrappedCon = (WrappedConnection) this.getDataSource().getConnection();
con = (OracleConnection) wrappedCon.getUnderlyingConnection();
byte[] bytes= IOUtils.toByteArray(input);
blobObj=con.createBlob(bytes);
execute(new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection con)
throws SQLException {
String procedure = "call SAVE_DATA(?,?)";
CallableStatement stm=con.prepareCall(procedure);
stm.setBlob(1, blobObj);
stm.setDate(2, date);
return stm;
}
}, new CallableStatementCallback<Map<Integer,Object>>() {
public Map<Integer, Object> doInCallableStatement(CallableStatement cs)
throws SQLException,DataAccessException {
cs.execute();
return null;
}}
);
con.commit();
con.close();
但是当我运行这部分代码时,我得到了来自 DB 端的下一个异常“ORA-22927 invalid LOB locator specified”