`

java xmltype

阅读更多

使用JDBC 访问XMLType 数据
  oracle.xdb.XMLType类的createXML()方法
   这是一个用于访问Oracle数据库,任何数据,包括在Oracle XML DB的XML文档的Java应用程序的基于SQL的方法。

 Java应用程序如何使用JDBC来访问在Oracle XML DB的XML文档
  JDBC的用户可以查询一个XMLType表,以获取一个JDBC的XMLType接口,支持通过SQL的XMLType数据类型支持的所有方法。在Java(JDBC)API 中 XMLType接口可以实现DOM文档的接口。

----------------------------------------------------------------------------
Example 12-1 XMLType Java: 使用JDBC 查询 XMLType 表
The following is an example that illustrates using JDBC to query an XMLType table:
 import oracle.xdb.XMLType;
  ...
 OraclePreparedStatement stmt = (OraclePreparedStatement)
 conn.prepareStatement("select e.poDoc from po_xml_tab e");
 ResultSet rset = stmt.executeQuery();
 OracleResultSet orset = (OracleResultSet) rset;
 while(orset.next())
 {
       // get the XMLType
       XMLType poxml = XMLType.createXML(orset.getOPAQUE(1));
       // get the XMLDocument as a string...
       Document podoc = (Document)poxml.getDOM();
  }

--------------------------------------------------------------------------------
Example 12-2 XMLType Java: Selecting XMLType Data
You can select the XMLType data in JDBC in one of two ways:
    (1)Use the getClobVal(), getStringVal() or getBlobVal(csid) in SQL and get the result as an oracle.sql.CLOB, java.lang.String or oracle.sql.BLOB in Java. The following Java code snippet shows how to do this:
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
 Connection conn =
    DriverManager.getConnection("jdbc:oracle:oci8:@", "scott", "tiger");
 OraclePreparedStatement stmt =
    (OraclePreparedStatement) conn.prepareStatement(
          "select e.poDoc.getClobVal() poDoc, "+
                  "e.poDoc.getStringVal() poString "+
          " from po_xml_tab e");
ResultSet rset = stmt.executeQuery();
OracleResultSet orset = (OracleResultSet) rset;
while(orset.next()){
// the first argument is a CLOB
oracle.sql.CLOB clb = orset.getCLOB(1);
// the second argument is a string..
// now use the CLOB inside the program
 }
(2) Use getOPAQUE() call in the PreparedStatement to get the whole XMLType instance, and use the XMLType constructor to construct an oracle.xdb.XMLType class out of it. Then you can use the Java functions on the XMLType class to access the data.

import oracle.xdb.XMLType;
 ...
 OraclePreparedStatement stmt =
    (OraclePreparedStatement) conn.prepareStatement(
          "select e.poDoc from po_xml_tab e");
  ResultSet rset = stmt.executeQuery();
  OracleResultSet orset = (OracleResultSet) rset;
  // get the XMLType
  XMLType poxml = XMLType(orset.getOPAQUE(1));
  // get the XML as a string...
  String poString = poxml.getStringVal();
----------------------------------------------------------------------------

Example 12-3 XMLType Java: 直接返回 XMLType 类型数据
该例显示使用getObject方法直接从ResultSet结果集获取XMLType数据。
这段代码是从ResultSet获取XMLType数据最简单的方式。

import oracle.xdb.XMLType;
...
PreparedStatement stmt =  conn.prepareStatement(
          "select e.poDoc from po_xml_tab e");
ResultSet rset = stmt.executeQuery();
while(rset.next())
{
// get the XMLType
XMLType poxml = (XMLType)rset.getObject(1);

// get the XML as a string...
String poString = poxml.getStringVal();
 }
----------------------------------------------------------------------------

使用JDBC 进行数据库XML 文档存储操作。可以使用JDBC进行更新、插入、和删除XMLType数据。
 注意:
  extract(), transform(),和 existsNode()方法仅工作在ThickJDBC driver下。 Thin JDBC driver并不支持所有的oracle.xdb.XMLType方法。然而,如果你不使用oracle.xdb.XMLType类和OCIdriver,你可能失去与XML的智能处理相关的性能优势。
  Example 12-5 XMLType Java: Updating, Inserting, or Deleting XMLType Data

Bind a CLOB or a string to an INSERT or UPDATE or DELETE statement, and use the XMLType constructor inside SQL to construct the XML instance:

OraclePreparedStatement stmt =
    (OraclePreparedStatement) conn.prepareStatement(
     "update po_xml_tab set poDoc = XMLType(?) ");

// the second argument is a string..
String poString = "<PO><PONO>200</PONO><PNAME>PO_2</PNAME></PO>";

// now bind the string..
stmt.setString(1,poString);
stmt.execute();
Use the setObject() or setOPAQUE() call in the PreparedStatement to set the whole XMLType instance:

import oracle.xdb.XMLType;
...
OraclePreparedStatement stmt =
    (OraclePreparedStatement) conn.prepareStatement(
        "update po_xml_tab set poDoc = ? ");

// the second argument is a string
String poString = "<PO><PONO>200</PONO><PNAME>PO_2</PNAME></PO>";
XMLType poXML = XMLType.createXML(conn, poString);

// now bind the string..
stmt.setObject(1,poXML);
stmt.execute();

分享到:
评论

相关推荐

    java中xml文件的处理及oracle中xmltype的插入和读取.pdf

    java中xml文件的处理及oracle中xmltype的插入和读取.pdf

    Java使用JDBC或MyBatis框架向Oracle中插入XMLType数据

    XMLType是Oracle支持的一种基于XML格式存储的数据类型,这里我们共同来探究Java使用JDBC或MyBatis框架向Oracle中插入XMLType数据的方法:

    详解Java解析XML的四种方法

    xml 解析方式有四种--DOM 、SAX、JDOM、DOM4J。

    java中xml文件的处理及oracle中xmltype的插入和读取.docx

    。。。

    玩转Java对象和XML之间的转换

    本代码主要是Java对象和Xml之间的转换实例代码,如果想具体指导代码是如何搭建的,可以参照http://blog.csdn.net/songdeitao/article/details/17304395这篇博文,这里的代码是和此对应的。

    XMLParsing:XML,解析,Java

    Java 解析 XML 文件  DOM 解析是将 XML 文件全部载入到内存,组装成一颗 DOM 树,然后通过节点以及节点之间的关系来解析 XML文件,与平台无关,Java 提供的一种基础的解析 XML 文件的 API,理解较简单,但是由于...

    webservice所需jar包

    XMLType.XSD_STRING,//参数类型:String ParameterMode.IN); //参数模式:'IN' or 'OUT' call.addParameter("arg1", //参数名 XMLType.XSD_STRING,//参数类型:String ParameterMode.IN); //参数模式:'IN'...

    ODAC 4.5.2.19

    Oracle Data Access Components08-Oct-03 New features in ODAC 4.50-------------------------------------------------- - XMLTYPE datatype support added - WideString support added to work with Unicode ...

    PLSQL Developer238页中文版使用手册

    4.6包声明和JAVA会话声明 4.7查看结果 4.8查看DBMS_OUTPUT 4.9查看HTP输出 4.10调试 4.11跟踪运行 4.12回归测试 5优化 5.1使用解释计划窗口 5.2自动统计 5.3PL/SQL概览图 5.4SQL跟踪 6专用SQL 6.1使用...

    C#实现实体类和XML相互转换

    一、实体类转换成XML 将实体类转换成XML需要使用XmlSerializer类的Serialize方法,将实体类序列化 public static string XmlSerialize(T obj) { using (StringWriter sw = new StringWriter()) ...

    Oracle PL/SQL programming(5th Edition)

    The new edition covers calls to Java methods from within PL/SQL programs, autonomous transactions, object type inheritance, and the new Timestamp and XMLType data types. There’s also more ...

    JavaEE 5.0 Tutorial.pdf

    The Java EE 5Tutorial For Sun Java System Application Server 9.1 Contents Preface .........................................................................................................................

    PLSQL Developer用户指南

    4.6 包声明和 JAVA 会话声明 ........23 4.7 查看结果集 .......24 4.8 查看 DBMS_OUTPUT ...24 4.9 查看 HTP 输出 ....24 4.10 调试 .24 4.11 跟踪运行 .........28 4.12 回归测试 .........29 5. 优化...30 5.1 ...

    PLSQL_Developer7.0中文帮助手册

    6.7 查看和编辑 XMLTYPE 列..44 6.8 直接查询导出..........44 6.9 保存 SQL 脚本..........44 6.10 创建标准查询..........45 7. 命令窗口...............................46 7.1 输入 SQL 语句和命令....46 7.2 ...

    plsql developer 7.0 最新中文手册(下载前请务必看说明)

    4.6 包声明和 JAVA 会话声明.........................................23 4.7 查看结果集....................................................24 4.8 查看 DBMS_OUTPUT............................................

    PLSQL中文手册(相当全面)

    4.6 包声明和 JAVA 会话声明.........................................23 4.7 查看结果集....................................................24 4.8 查看 DBMS_OUTPUT............................................

    plsql中文使用说明

    4.6 包声明和 JAVA 会话声明.........................................23 4.7 查看结果集....................................................24 4.8 查看 DBMS_OUTPUT............................................

Global site tag (gtag.js) - Google Analytics