How to store xml files in oracle as xmltype

public class writexmldb2
     public static void main(String args[]) throws SQLException, FileNotFoundException
          DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@172.24.198.131:1521:ncad","scott","tiger");
          OracleXMLSave oracleXMLSave = new OracleXMLSave(conn, "RK1");
          Reader xsltReader=new FileReader(new File("d:/input.xslt"));
          oracleXMLSave.setXSLT(xsltReader, null);
          oracleXMLSave.setRowTag("RK1");
          oracleXMLSave.insertXML(oracleXMLSave.getURL("d:/catalog.xml"));
          OracleXMLQuery query = new OracleXMLQuery(conn, "SELECT JOURNAL_TITLE, PUBLISHER, EDITION, " +"ARTICLE_SECTION, TITLE, AUTHOR FROM JOURNAL");
          Reader xsltReader1=new FileReader(new File("d:/output.xslt"));
          query.setXSLT(xsltReader1, null);
          query.setRowTag("RK1");
          String xmlString=query.getXMLString();
i wrote this one... but i am getting following errors
Exception in thread "main" oracle.xml.sql.OracleXMLSQLException: No rows to modify -- the row enclosing tag missing. Specify the correct row enclosing tag.
     at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2385)
     at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2257)
     at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1345)
     at writexmldb2.main(writexmldb2.java:18)

i also tried with following code. but this one also give some errors.
import oracle.sql.CLOB;
import oracle.xml.sql.dml.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.*;
import java.io.Writer;
import java.net.*;
public class xmlwritedb
public static void main(String args[]) throws SQLException, ClassNotFoundException
String tabName = "RK1"; // Table into which to insert XML data
String xmlData = "D:\\catalog.xml"; // XML document filename
Class.forName("oracle.jdbc.driver.OracleDriver");
// Initialize a JDBC connection
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@172.24.198.131:1521:ncad","scott","tiger");
insertXML( xmlData, conn);
//OracleXMLSave save = new OracleXMLSave(conn, tabName);
//System.out.println(" successfully inserted "/*rowCount
// " rows into "*/+ tabName);
conn.close();
public static CLOB getCLOB(String xmlData, Connection conn) throws SQLException{
     CLOB tempClob = null;
     try{
     // If the temporary CLOB has not yet been created, create new
     tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
     // Open the temporary CLOB in readwrite mode to enable writing
     tempClob.open(CLOB.MODE_READWRITE);
     // Get the output stream to write
     Writer tempClobWriter = tempClob.getCharacterOutputStream();
     // Write the data into the temporary CLOB
     tempClobWriter.write(xmlData);
     // Flush and close the stream
     tempClobWriter.flush();
     tempClobWriter.close();
     // Close the temporary CLOB
     tempClob.close();
     } catch(SQLException sqlexp){
     tempClob.freeTemporary();
     sqlexp.printStackTrace();
     } catch(Exception exp){
     tempClob.freeTemporary();
     exp.printStackTrace();
     return tempClob;
public static void insertXML(String xmlData, Connection conn) {
     CLOB clob = null;
     String query;
     // Initialize statement Object
     PreparedStatement pstmt = null;
     try{
     query = "INSERT INTO RK1 VALUES (XMLType(?))";
     // Get the statement Object
     pstmt = conn.prepareStatement(query);
     // xmlData is the string that contains the XML Data.
     // Get the CLOB object using the getCLOB method.
     clob = getCLOB(xmlData, conn);
     // Bind this CLOB with the prepared Statement
     pstmt.setObject(1, clob);
     // Execute the Prepared Statement
     if (pstmt.executeUpdate () == 1) {
     System.out.println ("Successfully inserted a Purchase Order !");
     } catch(SQLException sqlexp){
     sqlexp.printStackTrace();
     } catch(Exception exp){
     exp.printStackTrace();
errors;;;;;;;;;
java.sql.SQLException: ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00210: expected '<' instead of 'D'
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 0
ORA-06512: at line 1
     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
     at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
     at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
     at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:543)
     at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1027)
     at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2885)
     at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2957)
     at xmlwritedb.insertXML(xmlwritedb.java:70)
     at xmlwritedb.main(xmlwritedb.java:20)

Similar Messages

  • How to create xml file from Oracle and sending the same xml file to an url

    How to create xml file from Oracle and sending the same xml file to an url

    SQL/XML (XMLElement, XMLForest, XMLAgg, etc) and UTL_HTTP.
    Whether that works for you with the version of Oracle you have, your requirements, and needs is another story. A little detail goes a long way.

  • How to store XML data into Oracle Table

    I had trouble to store XML data into Oracle Table with XDK (Oracle 8.1.7 ). The error is:
    C:\XDK_Java_9_2\xdk\demo\java\Test>java testInsert Dept.xml
    <Line 1, Column 1>: XML-0108: (Fatal Error) Start of root element expected.
    Exception in thread "main" oracle.xml.sql.OracleXMLSQLException: Start of root element expected.
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2263)
    at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1333)
    at testInsert.main(testInsert.java:8)
    Here is my xml file:
    <?xml version = '1.0'?>
    <ROWSET>
    <ROW num="1">
    <DEPTNO>10</DEPTNO>
    <DNAME>ACCOUNTING</DNAME>
    <LOC>NEW YORK</LOC>
    </ROW>
    <ROW num="2">
    <DEPTNO>20</DEPTNO>
    <DNAME>RESEARCH</DNAME>
    <LOC>DALLAS</LOC>
    </ROW>
    <ROW num="3">
    <DEPTNO>30</DEPTNO>
    <DNAME>SALES</DNAME>
    <LOC>CHICAGO</LOC>
    </ROW>
    <ROW num="4">
    <DEPTNO>40</DEPTNO>
    <DNAME>OPERATIONS</DNAME>
    <LOC>BOSTON</LOC>
    </ROW>
    </ROWSET>
    and here is structure of table:
    Name Null? Type
    DEPTNO NOT NULL NUMBER(2)
    DNAME VARCHAR2(14)
    LOC VARCHAR2(13)
    and here is my Java Code:
    import java.sql.*;
    import oracle.xml.sql.dml.OracleXMLSave;
    public class testInsert{
         public static void main(String[] args) throws SQLException{
              Connection conn = getConnection();
              OracleXMLSave sav = new OracleXMLSave(conn,"scott.tmp_dept");
              sav.insertXML(args[0]);
              sav.close();
              conn.close();
         private static Connection getConnection()throws SQLException{
              DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
              Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@amt-ebdev01:1521:mydept","scott","tiger");
              return conn;
    Could you help me ? Thanks !

    The problem is that you need to pass avalid URL , Document...
    Please try this code instead:
    import java.net.*;
    import java.sql.*;
    import java.io.*;
    import oracle.xml.sql.dml.OracleXMLSave;
    public class testInsert
    public static void main(String[] args) throws SQLException{
    Connection conn = getConnection();
    OracleXMLSave sav = new OracleXMLSave(conn,"scott.temp_dept");
    URL url = createURL(args[0]);
    sav.insertXML(url);
    sav.close();
    conn.close();
    private static Connection getConnection()throws SQLException{
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dlsun1982:1521:jwxdk9i","scott","tiger");
    return conn;
    // Helper method to create a URL from a file name
    static URL createURL(String fileName)
    URL url = null;
    try
    url = new URL(fileName);
    catch (MalformedURLException ex)
    File f = new File(fileName);
    try
    String path = f.getAbsolutePath();
    // This is a bunch of weird code that is required to
    // make a valid URL on the Windows platform, due
    // to inconsistencies in what getAbsolutePath returns.
    String fs = System.getProperty("file.separator");
    if (fs.length() == 1)
    char sep = fs.charAt(0);
    if (sep != '/')
    path = path.replace(sep, '/');
    if (path.charAt(0) != '/')
    path = '/' + path;
    path = "file://" + path;
    url = new URL(path);
    catch (MalformedURLException e)
    System.out.println("Cannot create url for: " + fileName);
    System.exit(0);
    return url;

  • How to store image files in oracle DB

    Hi,
    I am new to working with database.
    Please let me know how to store image files in Database using insert command.
    Thanks,
    Ramesh Yakkala.

    Hi,
    You need to create a directory object to import these files:
    Take a look on the example below:
    eg:
    CREATE TABLE MY_IMAGE_TABLE (
    ID NUMBER,
    NAME VARCHAR2(20),
    IMAGE BLOB);
    CREATE OR REPLACE DIRECTORY IMAGES AS '/tmp';
    GRANT READ, WRITE ON DIRECTORY IMAGES TO PUBLIC;
    CREATE OR REPLACE PROCEDURE load_file_to_my_table (p_file_name IN MY_IMAGE_TABLE.NAME%TYPE) AS
    v_bfile BFILE;
    v_blob BLOB;
    BEGIN
    INSERT INTO MY_IMAGE_TABLE (id, name, image)
    VALUES (1, p_file_name, empty_blob())
    RETURN doc INTO v_blob;
    v_bfile := BFILENAME('IMAGES', p_file_name);
    Dbms_Lob.Fileopen(v_bfile, Dbms_Lob.File_Readonly);
    Dbms_Lob.Loadfromfile(v_blob, v_bfile, Dbms_Lob.Getlength(v_bfile));
    Dbms_Lob.Fileclose(v_bfile);
    COMMIT;
    END;
    SQL> execute load_file_to_my_table('myfhoto.jpg');Cheers

  • How to store XML files

    Hi experts,
    I have an abap applicatrion that has to store xml files received from a web service.
    Where is better to store these files, in sap transparent tables or in the IXOS for example?
    Thanks

    Brad,
    An java application will call that BAPI passing the XML when error occurs in the process. The XML will contain the error details.
    I want to associate the error messages with the respective XMLs.
    What do you mean with  "object type / object value" ?
    Thanks
    Edited by: Jorge Castro on Jan 18, 2011 5:09 PM

  • How to generate XML file from oracle database query result

    Hi dudes,
    as stated on the subject, can anyone suggests me how can i achieve the task stated above??
    Here is a brief description of my problem:
    I need to create a XML file once i query from the oracle database, and the query result returned from the database will be stored in XML file.
    I'd searched around the JAXB, DOM, SAXP and the like basic concepts, but i still don't know how to start??
    Any suggestions ???

    Read this:
    http://www.cafeconleche.org/books/xmljava/chapters/ch08s05.html
    You might have to read more of the book to understand that chapter.

  • How to store .doc file in oracle using jdbc

    Here is problem , storing microsoft excel file (or) .txt file to database(ORACLE) through JDBC .
    how to retrive

    Congratulations! You are the one millionth person to ask how to store files in databases without searching for previous threads.
    What do you win?
    A hearty smack in the forehead and a strenuous endorsement to use Google, search and find the answer.

  • How to store Html File in Oracle Table?

    Hai,
    I want to store Html File(s) into oracle Table. How can I do it?.
    Please help me. Html File size can be maximum 40 MB .
    Regards
    Suresh

    If it's just pure HTML it's nothing more than astring so you could store it as such.
    Most databases have a limitation on the maximum number
    of characters that a string can hold. With 30MB of
    text, a CLOB (Character Large OBject) is the
    preferrable type but a BLOB (Binary Large OBject) can
    also be used.
    ;o)
    V.V.Right, right. But, I kind of doubt that an html file takes up 30MB, can you imagine browsing a web site, regardless of your connection, with pages that size? We're talking ~125,000 line of pure HTML code (no images)!

  • How to store xml-file direct on file-directory on server ?

    Hello,
    I have created a xml-data by using xmlelements, xmlforest .... and so on in a sql-statement and want to store it as file in a ( windows) server-directory.
    I can find some samples to store it in XML-DB by using dbms_xmlGEN and dbms_XDB,
    but how to store it direct ?
    thank you
    Norbert

    Try dbms_xmldom.writeToFile()..
    Or create a resource from your SQL Statement using dbms_xdb.createResource() and then access the resource via FTP or HTTP

  • How to load XML files into oracle

    I am new to XML.I have a few XML files.I want to load them into oracle.I have oracle client on my win2000 machine version 8.1.6.3.
    I cannot find Loadjava.jar file in ORACLE_HOME\bin directory.
    Where is the XSU-dsl and the XDK utility?Do i need to down load it?

    This forum is dedicated to the XML Features of 9iR2, and to a lesser extent 9i. Questions related to XML and earlier versions of the database should be posted in Technologies -> General -> XML...
    I will move this thread to the appropriate forum if required.

  • How to store txt file into Oracle 7 Database using Pro*C

    Hi,
    I want to store a txt file into Oracle 7 database table using
    Pro*C application. But do not know what type of column to use.
    At first glance it appeared to me as LONG can serve the purpose
    but later I noticed that I can not do the sequential read/write
    in LONG type of column. That is, I have to use chunks of max of
    2GB (or file lenght) to read/write into such columns.
    I want something simiar to CLOB of Oracle 8.
    I would appreciate if you can provide me solution.
    Thanks,
    Anurag

    You store images in a BLOB column in the database.
    However, inserting image in that column and displaying data/image from that column are 2 very different tasks.
    If you are using Oracle forms, displaying is easy. Default block sitting on the table with BLOB column, can be easily mapped to image box (or similar control), which will display that image.
    Inserting images will be a different ball game. If your forms are web based (i.e. run from browser) and you want to insert images from client machine, some special arrangements are required.
    If images are on database server and you want to insert them in database, the stored procedure given in the earlier thread (posted above) will do the job.

  • How to store .xml file in mime repository.

    I AM USING CL_MIME_REPOSITORY_API
    TO UPLOAD FILE TO MIME REPOSITORY
    it shows the following outcome
    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
    Element was not closed. Error processing resource 'file:///C:/Documents and Settings/User/Local Settings/Temp/a9c41e8HTML00...
    <?xml version="1.0"?><TY_CUSTAC><TY_CUSTAC><CUSTNO Datatype="C" Length="20">0000000001</CUSTNO>...
    i am unable to read it in xml format any help will be appriciated.
    Edited by: SAMI ABAP on Apr 15, 2010 12:36 PM

    Hi,
    Uploading XML file in the repository takes lot of space, check whether you have it or else request the concerned person to extend the space or to create another directory with bigger space.
    Regards,
    Ni3

  • How to Load XML files into Oracle 8 database.

    My company is currently using Oracle Aplications V. 10.7 character mode and intend to migrate to V.11.0.3 in the next months.
    We want to import data (XML format) in the OE module using Open Interfaces.
    How to proceed ?

    This forum is dedicated to the XML Features of 9iR2, and to a lesser extent 9i. Questions related to XML and earlier versions of the database should be posted in Technologies -> General -> XML...
    I will move this thread to the appropriate forum if required.

  • How to export a data as an XML file from oracle data base?

    could u pls tell me the step by step procedure for following questions...? how to export a data as an XML file from oracle data base? is it possible? plz tell me itz urgent requirement...
    Thankz in advance
    Bala

    SQL> SELECT * FROM v$version;
    BANNER
    Oracle DATABASE 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS FOR 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    5 rows selected.
    SQL> CREATE OR REPLACE directory utldata AS 'C:\temp';
    Directory created.
    SQL> declare                                                                                                               
      2    doc  DBMS_XMLDOM.DOMDocument;                                                                                       
      3    xdata  XMLTYPE;                                                                                                     
      4                                                                                                                        
      5    CURSOR xmlcur IS                                                                                                    
      6    SELECT xmlelement("Employee",XMLAttributes('http://www.w3.org/2001/XMLSchema' AS "xmlns:xsi",                       
      7                                  'http://www.oracle.com/Employee.xsd' AS "xsi:nonamespaceSchemaLocation")              
      8                              ,xmlelement("EmployeeNumber",e.empno)                                                     
      9                              ,xmlelement("EmployeeName",e.ename)                                                       
    10                              ,xmlelement("Department",xmlelement("DepartmentName",d.dname)                             
    11                                                      ,xmlelement("Location",d.loc)                                     
    12                                         )                                                                              
    13                   )                                                                                                    
    14     FROM   emp e                                                                                                       
    15     ,      dept d                                                                                                      
    16     WHERE  e.DEPTNO=d.DEPTNO;                                                                                          
    17                                                                                                                        
    18  begin                                                                                                                 
    19    OPEN xmlcur;                                                                                                        
    20    FETCH xmlcur INTO xdata;                                                                                            
    21    CLOSE xmlcur;                                                                                                       
    22    doc := DBMS_XMLDOM.NewDOMDocument(xdata);                                                                           
    23    DBMS_XMLDOM.WRITETOFILE(doc, 'UTLDATA/marco.xml');                                                                  
    24  end;                                                                                                                  
    25  /                                                                                                                      
    PL/SQL procedure successfully completed.
    .

  • How to export an XML file from oracle database?

    plz help me its urgent requirement....could u pls tell me the step by step procedure for following questions...?how to export a data as an XML file from oracle database?
    thanks in advance,
    Bala.
    Edited by: user3523292 on Nov 14, 2008 5:43 AM

    user3523292 wrote:
    plz help me its urgent requirement....could u pls tell me the step by step procedure for following questions...?how to export a data as an XML file from oracle database?
    thanks in advance,
    Bala.
    Edited by: user3523292 on Nov 14, 2008 5:43 AMThis is a forum of volunteers. There is no "urgent" here. Nevertheless, a google search of 'xml oracle export' quickly lead me to this Oracle site:
    otn.oracle.com/sample_code/tech/xml/index.html
    I also see lots of hits when I search the documentation library at tahiti.oracle.com for 'xml'. This one in particular may be what you are looking for:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14252/adx_j_xsu.htm#ADXDK070

Maybe you are looking for

  • Hii all, how  can we create a report for purchase tax register

    Purchase Tax Register 2:        Fields on selection screen (input screen) : Vendor Code from to , Date from to, Material Type from to, Tax Code from to .              Field in the output List : Document Number , PO Number ,PO      Date ,     Vendor C

  • Regarding inventory management

    Hi, I have documnet How To Handle Inventory Management Scenarios in BW Version 1.3 – January 2005. But it gives the details about 3.5 version. If i want to implemnet in 7.0 what all i need? also i w2as trying to find the 'No marker update' option and

  • AJAB  Can REOPEN again?

    Hello all: If I do wrong closing, can I re-open fiscal year already closed again? Best Regards, Manthana

  • Branch flow in two parallel notifications

    Hi all, I've already posted something like this, but i think this explanation is a little clearer than the old one. is it possible to branch the flow in two parallel notifications? My workflow has a function that evaluates attributes, an in some case

  • Xcode 4 - last build phase "copy files" gets build stuck

    I really like the new XCode, but I'm having one really annoying issue. When I try to add new build phase "Copy Files" after every other build phases, which copies the final product component to some directory, the build just gets stuck. This is what