简体   繁体   English

Java:Oracle XMLType + JDBC

[英]Java: Oracle XMLType + JDBC

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. 基本上,我想读取像<name> </name>这样的String或任何XML格式的输出。 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. 只有奇怪的oracle.sql.OPAQUE有效,但我完全不知道如何处理它。 Even toString() is not overriden! 甚至toString()也没有被覆盖!

Any ideas? 有任何想法吗? How to read Oracle's (I am using Oracle 10.0.2) XMLElement (XMLType) ? 如何阅读Oracle(我使用的是Oracle 10.0.2)XMLElement(XMLType)?

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类中作为String访问

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM