简体   繁体   English

我必须配置哪些设置才能使用XML作为输入使用Spring的存储过程与Oracle相关的参数

[英]Which settings do I have to configure to use XML as input Parameter with Oracle using Spring's stored procedure

I have a spring application which needs to execute a stored procedure with an XML IN parameter. 我有一个spring应用程序,需要使用XML IN参数执行存储过程。 The stored procedure is declared as follows: 存储过程声明如下:

private class InsertXMLDataProcedure extends StoredProcedure {

    public InsertXMLDataProcedure(DataSource ds) {
        super(ds, PROCEDURE_NAME);
        declareParameter(new SqlParameter("COMPANYNO", Types.INTEGER));
        declareParameter(new SqlParameter("XMLDATA", Types.SQLXML));
        declareParameter(new SqlParameter("ERRORNO", Types.INTEGER));
        declareParameter(new SqlParameter("ERRORDESC", Types.VARCHAR));
        compile();
    }

    public Map<String, Object> execute(int companyNumber, String xmlData, int errorNumber, String errorDescription) {
        return super.execute(companyNumber, xmlData, errorNumber, errorDescription);
    }
}

However, the XML input isn't inserted into the table. 但是,XML输入未插入表中。 Apparently, Oracle requires vendor specific configuration settings to recognise the input. 显然,Oracle需要供应商特定的配置设置才能识别输入。

OK, so fixing this was a small dependency abomination, due to Oracle's byzantine library publishing habits. 好吧,由于甲骨文的拜占庭图书馆出版习惯,解决这个问题是一个很小的依赖性憎恶。

The code changes as such are relatively minimal: 代码更改因此相对最小:

private class InsertXMLDataProcedure extends StoredProcedure {

    public InsertXMLDataProcedure(DataSource ds) {
        super(ds, PROCEDURE_NAME);
        declareParameter(new SqlParameter("COMPANYNO", Types.INTEGER));
        declareParameter(new SqlParameter("XMLDATA", OracleTypes.OPAQUE, "SYS.XMLTYPE"));
        declareParameter(new SqlParameter("ERRORNO", Types.INTEGER));
        declareParameter(new SqlParameter("ERRORDESC", Types.VARCHAR));
        compile();
    }

    public Map<String, Object> execute(int companyNumber, String xmlData, int errorNumber, String errorDescription) {
        return super.execute(companyNumber, new OracleXmlTypeValue(xmlData), errorNumber, errorDescription);
    }
}

It basically comes down to changing the paramter type to: 它基本上归结为将参数类型更改为:

new SqlParameter("XMLDATA", OracleTypes.OPAQUE, "SYS.XMLTYPE")

and wrapping the xml into a OracleXmlTypeValue object. 并将xml包装到OracleXmlTypeValue对象中。

Both of which are available in spring's spring-data-oracle extension. 这两个都在spring的spring-data-oracle扩展中可用。 The maven dependency at the time of writing is as follows: 撰写本文时的maven依赖关系如下:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-oracle</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

Now that was the easy bit. 现在这很简单。 You will also have to provide a set of jars to make this work. 您还必须提供一组罐子才能完成这项工作。 These are not in any maven repository, you'll have to install them locally or upload them to your local nexus. 这些不在任何maven存储库中,您必须在本地安装它们或将它们上传到您的本地连接。

The jars in question are: 有问题的罐子是:

  • xdb6.jar xdb6.jar
  • xmlparserv2.jar xmlparserv2.jar

xdb6.jar is available from Oracle Technology Network (OTN) on the Oracle driver download page, located at http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html . 可从Oracle技术网络(OTN)的Oracle驱动程序下载页面上获得xdb6.jar,该驱动程序位于http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html上

xmlparserv2.jar is much harder to find. xmlparserv2.jar更难找到。 If you're lucky, you'll find it in {ORACLE_HOME}/oracle/produce/{VERSION_NUMBER}/lib/xmlparserrv2.jar on your database machine. 如果幸运的话,您可以在数据库计算机上的{ORACLE_HOME}/oracle/produce/{VERSION_NUMBER}/lib/xmlparserrv2.jar找到它。 If not, like me, you'll find it packaged with Jdeveloper, which is obtainable here: http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html - you should pick the Java Edition, the jar's in modules/oracle.xdk_12.1.3 . 如果不是这样,就像我一样,您会发现它与Jdeveloper打包在一起,可以从以下位置获得: http : //www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html-您应该选择Java版本,jar在modules/oracle.xdk_12.1.3

Do not try to download XDK directly, it's an old version. 不要尝试直接下载XDK,它是旧版本。 Using that library will give java.lang.NoClassDefFoundError: oracle/xml/binxml/BinXMLMetadataProvider . 使用该库将提供java.lang.NoClassDefFoundError: oracle/xml/binxml/BinXMLMetadataProvider Oracle quietly changed the contents of xmlparserv2.jar whithout bumping the version; Oracle悄悄更改了xmlparserv2.jar的内容,而没有增加版本; as I said byzantine habits. 正如我所说的拜占庭习惯。

NB all of this applies to Oracle 11 and higher. 注意,所有这些都适用于Oracle 11及更高版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在 Oracle 数据库中有一个 SQL 存储过程,参数为时间戳。 如何调用程序 - I have a SQL Stored procedure in Oracle database with parameter as timestamp. How to call the procedure Oracle 11g:使用简单的 jdbc 调用将数组作为输入参数传递给 oracle 存储过程 - Oracle 11g: Pass array as input parameter to an oracle stored procedure using simple jdbc call 使用spring存储过程调用oracle存储过程 - Calling oracle stored procedure using spring stored procedure 在XML中使用Hibernate调用Oracle存储过程 - Calling Oracle stored procedure using hibernate in xml 如何使用JDBC / Spring调用Oracle存储过程,其中一些参数类型是用户定义的? - How can I call an Oracle stored procedure with JDBC/Spring where some of the parameter types are user defined? 使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程 - Pass array as input parameter to an oracle stored procedure using simple jdbc call 使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程 - Pass array as input parameter to an oracle stored procedure using simple jdbc call 在MySQL中,如何获取存储过程的第一个输入参数的参数名称? - In MySQL, How get I get the parameter name of a stored procedure's first input parameter? Ubuntu-为什么我有那么多Oracle Java 7,应该使用哪一个? - Ubuntu - Why do I have so many Oracle Java 7s, and which one should I be using? 使用Spring的org.springframework.jdbc.object.StoredProcedure调用Oracle存储过程 - call Oracle stored procedure using Spring's org.springframework.jdbc.object.StoredProcedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM