[英]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 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.