Java:从StoredProcedure返回XMLType数据,使用ojdbc6。jar xdb6。jar xmlparserv2。用于Java到PLSQL交互的jar

时间:2020-12-25 02:07:04

I am following the below tutorial to retrieve XMLType data from a stored procedure

下面的教程将从存储过程中检索XMLType数据

http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb11jav.htm#g1039140Example 13-4 XMLType Java: Returning XMLType Data

http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb11jav.htm# g1039140例13-4 XMLType Java:返回XMLType数据

When I run the code, I get this error,

当我运行代码时,我得到这个错误,

Exception in thread "main" java.lang.NoClassDefFoundError: oracle/xml/parser/v2/XMLParseException    at oracle.xdb.XMLTypeFactory.create(XMLTypeFactory.java:67)    at oracle.sql.OPAQUE.toClass(OPAQUE.java:328)    at oracle.sql.OPAQUE.toJdbc(OPAQUE.java:278)    at oracle.sql.OPAQUE.toJdbc(OPAQUE.java:259)    at oracle.jdbc.driver.NamedTypeAccessor.getObject(NamedTypeAccessor.java:190)    at oracle.jdbc.driver.NamedTypeAccessor.getObject(NamedTypeAccessor.java:117)    at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:1579)    at oracle.jdbc.driver.OracleCallableStatementWrapper.getObject(OracleCallableStatementWrapper.java:815)    at com.example.TestXMLDAO.main(TestXMLDAO.java:48)Caused by: java.lang.ClassNotFoundException: oracle.xml.parser.v2.XMLParseException    at java.net.URLClassLoader$1.run(Unknown Source)    at java.security.AccessController.doPrivileged(Native Method)    at java.net.URLClassLoader.findClass(Unknown Source)    at java.lang.ClassLoader.loadClass(Unknown Source)    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)    at java.lang.ClassLoader.loadClass(Unknown Source)    ... 9 more

Java code snippet:

Java代码片段:

import java.io.IOException;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import oracle.jdbc.OracleTypes;import oracle.xdb.XMLType;

.............

.............

            // Prepare to call the stored procedure get_group_details.            String sql = "{call mypackage.get_records(?,?,?,?,?,?,?,?)}";            callableStatement = conn.prepareCall(sql);            callableStatement.setString(1, "");            callableStatement.setString(2, "");            callableStatement.setString(3, "");            callableStatement.setString(4, "");            callableStatement.setString(5, "abb%");            callableStatement.setString(6, "F");            callableStatement.setString(7, "F");            callableStatement.registerOutParameter(8, OracleTypes.OPAQUE,                    "SYS.XMLTYPE");            // execute get_group_details            // callableStatement.executeQuery();            callableStatement.executeQuery();            callableStatement.getObject(8);            // get cursor and cast it to ResultSet            xml = (XMLType) callableStatement.getObject(8);            System.out.println(xml.getStringVal());        } catch (Exception ex) {            ex.printStackTrace();        } finally {            // Close the statement            callableStatement.close();            // Close the connection            conn.close();        }

PLSQL Procedure snippet

PLSQL程序片段

PROCEDURE get_records   (      grp1     IN a.name%TYPE DEFAULT NULL     ,grp2 IN a.name%TYPE DEFAULT NULL     ,grp3        IN a.name%TYPE DEFAULT NULL     ,grp4          IN a.name%TYPE DEFAULT NULL     ,grp5               IN a.name%TYPE DEFAULT NULL     ,flag1     IN a.flag%TYPE DEFAULT 'F'     ,flag2       IN a.flag%TYPE DEFAULT 'F'     ,xml_type_out        OUT xmltype   );

Jars included: ojdbc6.jar, xdb.jar

jar包括:ojdbc6。jar,xdb.jar

Any idea what I am missing?

知道我错过了什么吗?

This issue is resolved. But when deployed in JBoss server, another issue - please refer here if you have any ideas - Xmlparserv2 error while application deployed in jboss, Installing Oracle ojdbc module in JBoss for Java web application

这个问题得到解决。但是当部署到JBoss服务器时,另一个问题——如果您有任何想法,请在这里参考——Xmlparserv2错误,应用程序在JBoss中部署,在Java web应用程序的JBoss中安装Oracle ojdbc模块

3 个解决方案

#1


12  

Issue fixed by adding the required jars

通过添加所需的jar文件来修复问题

Needed the following three jars in the classpath, [I had these jars still, I was getting error due to wrong versions of the jar]

在类路径中需要以下三个jar,[我仍然有这些jar,由于jar的错误版本,我得到了错误的结果]

ojdbc6.jar, xdb6.jar, xmlparserv2-11.1.1.jar

ojdbc6。xdb6 jar。jar,xmlparserv2-11.1.1.jar

Even if you have these jars, you might get error like I was getting when I was including a wrong version of xmlparserv2.jar.

即使您有这些jar,您也可能会得到错误,就像我在包含xmlparserv2.jar的错误版本时所得到的错误一样。

So Important thing to take care is the version and compatibility of these jars.

需要注意的是这些jar的版本和兼容性。

The ones that worked for me [My Oracle DB version : 11.2.0.4.0]

为我工作的人[我的Oracle DB版本:11.2.0.4.0]

ojdbc6.jar; xdb6.jar:

ojdbc6.jar;xdb6.jar:

http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

http://www.oracle.com/technetwork/database/enterprise edition/jdbc - 112010 - 090769. - html

xmlparserv2-11.1.1.jar available here: ( SQL Developer ) (in sqldeveloper\modules\oracle.xdk_12.1.2)

xmlparserv2-11.1.1。(SQL Developer)(在sqldeveloper\模块中)\oracle.xdk_12.1.2)

[removed third party reference link as advised by @Lukas Eder, Thanks for that]

[删除了@Lukas Eder建议的第三方参考链接,谢谢]

#2


6  

There's a distribution of xmlparserv2.jar in various Oracle products, among which SQL Developer (in sqldeveloper\modules\oracle.xdk_12.1.2).

这是xmlparserv2的分布。jar在各种Oracle产品中,其中包括SQL Developer (sqldeveloper\模块\oracle.xdk_12.1.2)。

Of course, I have no clue if you're allowed to extract that jar from SQL Developer, license wise.

当然,我不知道是否允许您从SQL Developer中提取jar。

#3


1  

Class

oracle.xml.parser.v2.XMLParseException

is in xmlparserv2.jar

在xmlparserv2.jar

Available at http://www.oracle.com/us/downloads/index.html

可以在http://www.oracle.com/us/downloads/index.html

#1


12  

Issue fixed by adding the required jars

通过添加所需的jar文件来修复问题

Needed the following three jars in the classpath, [I had these jars still, I was getting error due to wrong versions of the jar]

在类路径中需要以下三个jar,[我仍然有这些jar,由于jar的错误版本,我得到了错误的结果]

ojdbc6.jar, xdb6.jar, xmlparserv2-11.1.1.jar

ojdbc6。xdb6 jar。jar,xmlparserv2-11.1.1.jar

Even if you have these jars, you might get error like I was getting when I was including a wrong version of xmlparserv2.jar.

即使您有这些jar,您也可能会得到错误,就像我在包含xmlparserv2.jar的错误版本时所得到的错误一样。

So Important thing to take care is the version and compatibility of these jars.

需要注意的是这些jar的版本和兼容性。

The ones that worked for me [My Oracle DB version : 11.2.0.4.0]

为我工作的人[我的Oracle DB版本:11.2.0.4.0]

ojdbc6.jar; xdb6.jar:

ojdbc6.jar;xdb6.jar:

http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

http://www.oracle.com/technetwork/database/enterprise edition/jdbc - 112010 - 090769. - html

xmlparserv2-11.1.1.jar available here: ( SQL Developer ) (in sqldeveloper\modules\oracle.xdk_12.1.2)

xmlparserv2-11.1.1。(SQL Developer)(在sqldeveloper\模块中)\oracle.xdk_12.1.2)

[removed third party reference link as advised by @Lukas Eder, Thanks for that]

[删除了@Lukas Eder建议的第三方参考链接,谢谢]

#2


6  

There's a distribution of xmlparserv2.jar in various Oracle products, among which SQL Developer (in sqldeveloper\modules\oracle.xdk_12.1.2).

这是xmlparserv2的分布。jar在各种Oracle产品中,其中包括SQL Developer (sqldeveloper\模块\oracle.xdk_12.1.2)。

Of course, I have no clue if you're allowed to extract that jar from SQL Developer, license wise.

当然,我不知道是否允许您从SQL Developer中提取jar。

#3


1  

Class

oracle.xml.parser.v2.XMLParseException

is in xmlparserv2.jar

在xmlparserv2.jar

Available at http://www.oracle.com/us/downloads/index.html

可以在http://www.oracle.com/us/downloads/index.html