BLOB和jdbc:stored-proc-outbound-gateway

时间:2016-08-31 14:48:17

标签: java spring oracle jdbc spring-integration

通过以下方式调用我的存储过程

我的过程包含一个包含一个BLOB对象的对象集合。 当我将BLOB对象传递为null时,它可以正常工作。 但尝试使用blob值更新BLOB对象获取oracle错误 "ORA-22922: nonexistent LOB value"

在我的XML下面找到                                         

<int:channel id="input" />
<int:channel id="output"></int:channel>

<int-jdbc:stored-proc-outbound-gateway 
    data-source="dataSource"    request-channel="input" reply-channel="output"
    stored-procedure-name="PKG_FIEL_CUST.PRC_FIEL_UPDATE_CERT" expect-single-result="false"
    ignore-column-meta-data="true" return-value-required="false">
    <int-jdbc:sql-parameter-definition  name="iv_v_user_id"  direction="IN" type="VARCHAR"/>
    <int-jdbc:sql-parameter-definition  name="GV_TB_FIEL_CUST_DEF"  direction="IN" type="ARRAY"/>
    <int-jdbc:sql-parameter-definition name="ov_v_error_code"  direction="OUT"  />
    <int-jdbc:sql-parameter-definition name="ov_v_error_desc"  direction="OUT"  />
    <int-jdbc:parameter  name="iv_v_user_id" value="FMT" />
    <int-jdbc:parameter name="GV_TB_FIEL_CUST_DEF" expression="payload"/>       

</int-jdbc:stored-proc-outbound-gateway>
    <int:service-activator input-channel="output"  ref="jdbcHandler"></int:service-activator>

和我的java类

public class JdbcOutboundTest {
public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "jdbc-outbound.xml");
    DirectChannel input = context.getBean("input", DirectChannel.class);

    DriverManagerDataSource datasour = context.getBean("dataSource",
            DriverManagerDataSource.class);

    Connection connection = datasour.getConnection();

    String s = "jjdfdjsvgkljdfskvfkldnv";
    Blob byteblob = connection.createBlob();
    byteblob.setBytes(1, s.getBytes());

    Date curDate = new Date(System.currentTimeMillis());

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
    java.sql.Date dtValue = new java.sql.Date(sdf.parse(curDate.toString())
            .getTime());
    System.out.println(dtValue);
    List<Object> java_record_array = new ArrayList<>(25);

    java_record_array.add(0, "03232323232323232");
    java_record_array.add(1, "0");
    java_record_array.add(2, "GGGG");
    java_record_array.add(3, "freefefrr343423232323");
    java_record_array.add(4, dtValue);

    java_record_array.add(5, dtValue);
    java_record_array.add(6, "edjijifk");
    java_record_array.add(7, byteblob);
    java_record_array.add(8, "MX");
    java_record_array.add(9, "Tlalpan");
    java_record_array.add(10, "XXXX");
    java_record_array.add(11, "YYYYYY");
    java_record_array.add(12, "14210");
    java_record_array.add(13, "OOOOOO");

    java_record_array.add(14, "FFFFFFF");

    java_record_array.add(15, "sdj");
    java_record_array.add(16, "sdj");
    java_record_array.add(17, "sdj");
    java_record_array.add(18, "sdj");
    java_record_array.add(19, "P");
    java_record_array.add(20, "P");

    java_record_array.add(21, "sdf");
    java_record_array.add(22, "0");
    java_record_array.add(23, "akdj");
    java_record_array.add(24, "ammhi");
    ARRAY oracle_array = (ARRAY) getObjects(java_record_array, connection);

    Message<ARRAY> message = MessageBuilder.withPayload(oracle_array)
            .build();

    input.send(message);
    // CommonDBUtil.closeDataBaseResources(connection, stmt);
}

private static oracle.sql.ARRAY getObjects(List<Object> java_record_array,
        Connection connection) {
    ARRAY body_array = null;
    Object[] java_record_array_1 = new Object[25];
    ;
    Object[] record_array = new Object[1];
    int i = 0;
    try {
        StructDescriptor recDescriptor = StructDescriptor.createDescriptor(
                "GV_OB_FIEL_CUST_DEF", connection);
        ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
                "GV_TB_FIEL_CUST_DEF", connection);

        for (Object obj : java_record_array) {
            java_record_array_1[i] = obj;
            i = i + 1;
        }

        STRUCT body_record = new STRUCT(recDescriptor, connection,
                java_record_array_1);
        record_array[0] = body_record;
        body_array = new ARRAY(arrayDescriptor, connection, record_array);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return body_array;
}

}

请帮助解决上述问题。

0 个答案:

没有答案