Java:Oracle XMLType + JDBC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4318900/
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: Oracle XMLType + JDBC
提问by Xorty
How can I get oracle XMLElement to JDBC?
如何将 oracle XMLElement 获取到 JDBC?
java.sql.Statement st = connection.createStatement(); // works
oracle.jdbc.OracleResultSet rs = st.execute("SELECT XMLElement("name") FROM dual");
rs.getString(1); // returns null, why?
oracle.sql.OPAQUE = (OPAQUE) rs.getObject(1); // this works, but wtf is OPAQUE ?
Basically, I want to read String like <name> </name>
or whatever XML formatted output. But I always fail to cast output to anything reasonable. Only weird oracle.sql.OPAQUE works, but I totally dont know what to do with that. Even toString()
is not overriden!
基本上,我想读取类似字符串<name> </name>
或任何 XML 格式的输出。但我总是无法将输出转换为任何合理的值。只有奇怪的 oracle.sql.OPAQUE 有效,但我完全不知道该怎么办。即使toString()
没有被覆盖!
Any ideas? How to read Oracle's (I am using Oracle 10.0.2) XMLElement (XMLType) ?
有任何想法吗?如何阅读 Oracle 的(我使用的是 Oracle 10.0.2)XMLElement (XMLType)?
回答by a_horse_with_no_name
You can't. Oracle's JDBC driver does not support the JDBC XML type properly.
你不能。Oracle 的 JDBC 驱动程序不正确支持 JDBC XML 类型。
The only thing you can do, is to convert the XML as part of the query:
您唯一能做的就是将 XML 作为查询的一部分进行转换:
SELECT to_clob(XMLElement("name")) from dual
Then you can retrieve the XML using getString()
然后您可以使用 getString() 检索 XML
alternatively you can also use XMLElement("name").getClobVal()
, but again this is part of your query and it can be accessed as a String from within your Java class
或者,您也可以使用XMLElement("name").getClobVal()
,但这也是您查询的一部分,可以从 Java 类中作为字符串访问
回答by no_name
ORA-1652: unable to extend temp segment by 128 in tablespace temp is a totally different error, nothing to be with XMLElement.
ORA-1652: 无法在表空间 temp 中将临时段扩展 128 是一个完全不同的错误,与 XMLElement 无关。
It is just that you hava to set your temp file to auto resize or give it a bigger size:
只是您需要将临时文件设置为自动调整大小或给它更大的大小:
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/product/10.2.0/db_1/oradata/oracle/temp01.dbf' SIZE 10M AUTOEXTEND ON
ALTER DATABASE TEMPFILE '/u01/app/oracle/product/10.2.0/db_1/oradata/oracle/temp01.dbf' RESIZE 200M