oracle Java:从 StoredProcedure 返回 XMLType 数据,使用 ojdbc6.jar xdb6.jar xmlparserv2.jar 用于 Java 到 PLSQL 交互
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25208239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java: Returning XMLType Data from StoredProcedure, Usage of ojdbc6.jar xdb6.jar xmlparserv2.jar for Java to PLSQL interaction
提问by spiderman
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.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
包含的罐子: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 服务器中时,另一个问题 - 如果您有任何想法,请参考这里 -在 jboss 中部署应用程序时 Xmlparserv2 错误,在 JBoss 中为 Java Web 应用程序安装 Oracle ojdbc 模块
回答by spiderman
Issue fixed by adding the required jars
通过添加所需的 jars 解决了问题
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.jar、xdb6.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]
对我有用的那些 [My 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.jaravailable here: ( SQL Developer) (in sqldeveloper\modules\oracle.xdk_12.1.2)
xmlparserv2-11.1.1.jar在此处可用:(SQL Developer)(在 sqldeveloper\modules\oracle.xdk_12.1.2 中)
[removed third party reference link as advised by @Lukas Eder, Thanks for that]
[根据@Lukas Eder 的建议删除了第三方参考链接,谢谢]
回答by Lukas Eder
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\modules\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,许可明智。
回答by laune
Class
班级
oracle.xml.parser.v2.XMLParseException
is in xmlparserv2.jar
在 xmlparserv2.jar 中
Available at http://www.oracle.com/us/downloads/index.html