Big XML document as blob in firebird database

Hi! I'm having some problems trying to use blob to store an XML document on a Firebird database. I'll try to make this simple: I'm reading a CD and copying the structure to an xml document (org.w3c.dom.Document), and i need to store it on a firebid database. The thing is that the document is really huge and when i try to insert it as text i get an exception:
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544726. Error reading data from the connection.
Reason: Error reading data from the connection.
Here is the code to insert:
StringBuffer buffer = new StringBuffer();
        printDOM(catalog.getXMLDom(), buffer);
        new DBInsert("INSERT INTO CD (NAME, CATEGORY, CATALOG_TYPE, CATALOG_DESCRIPTION, CATALOG_UBICATION, CATALOG_FORMAT, XML) VALUES ('" + catalog.getName() + "','" + category + "','" + catalog.getCatalogType() + "','" + catalog.getCatalogDescription() + "','" + catalog.getCatalogUbication() + "','" + catalog.getCatalogFormat() + "','" + buffer.toString() + "')"); The buffer has all the xml structure which i took from the Document object, and when i read from the database it's supposed to restore the document from the xml structure.
I'd be very happy if someone gives me a clue with that :) I have no idea how to insert and how to read the blob. The database column is defined with this domain CREATE DOMAIN BXML AS
BLOB SUB_TYPE 1 SEGMENT SIZE 4096 CHARACTER SET NONE;
Thanks for your time!
Fede
Edited by: fedebobbio1 on Dec 5, 2007 6:24 PM

See the document demo for the XSQL Servlet.
If it inserts an xml document into the database as a blob.

Similar Messages

  • Convert flat file to XML document and store into Oracle database

    First:
    I have a flatfile and created external table to read that file in Oracle
    Now I want to create an XML document for each row and insert into Oracle database, I think that XMLtype.
    Could you please provide me some information/steps.
    Second:
    Is there performance issues, because everyday I need to check that XML document stored in the database against the in coming file.
    Thank You.

    Oracle 11g R2 Sun Solaris
    Flat file is | (pipe delimited), so I did create an EXTERNAL Table
    row1     a|1|2|3|4
    row2     b|2|3|4|5
    row3     c|6|7|8|9
    I want to store each record as XML document. So it will be easy to compare with next day's load and make insert or update.
    The reason is:
         First day the file comes with 5 columns
         after some days, the file may carry on some additional columns more than 5
         In this case I do not want to alter table to capture those values, if I use XML than I can capture any number of columns, CORRECT!. Please make me correct If I am wrong.
         This is the only reason to try to use the XMLType (XML Document)
         On Everyday load we will be matching these XML documents and update it if there is any column's value changes
    daily average load will be 10 millions and initial setup will be 60-80 millions
         Do I have anyother option to capture the new values without altering the table.
    Please advise!.

  • How to save sections of a single XML Document to multiple tables ?

    Firstly, I apologise for the long e-mail but I feel it's necessary in order to clarify my problem/question.
    The XML document representation below stores information about a particular database. From the information in the XML document you can tell that there is a single database called "tst" which contains a single table called "tst_table". This table in turn has two columns called "CompanyName" & "Country".
    I want to use Oracle's XML SQL Utility to store this information into three seperate database tables. Specifically, I want to store the information pertaining to the database (i.e. name etc.) in one table, the information pertaining to the table (name, no. of columns etc.) in another and the information pertaining to the columns (name, type etc.) in yet another table.
    I have seen samples where an entire XML Document is saved to a database table but I cannot find any examples where different sections of a single XML Document are saved into different database tables using the XML SQL Utility.
    Can you please tell me the best approach to take in order to accomplish this . Does it involve creating an XMLDocument and then extracting the relevant sections as XMLDocumentFragment's, retrieving the String representations of these XMLDocumentFragment's and passing these strings to the OracleXMLSave.insertXml() method.
    Is this the best approach to take or are there any other, perhaps more efficient or elegant, ways of doing this ?
    Thanks in advance for your help
    - Garry
    <DATABASE id="1" name="tst">
    <TABLES>
    <TABLE name="tst_table">
    <NAME>Customers</NAME>
    <COLUMNS>
    <COLUMN num="1"> <COLID>2</COLID>
    <COLNAME>CompanyName</COLNAME>
    <COLTYPE>Text</COLTYPE>
    </COLUMN>
    <COLUMN num="2">
    <COLID>3</COLID>
    <COLNAME>Country</COLNAME>
    <COLTYPE>Text</COLTYPE>
    </COLUMN>
    </COLUMNS>
    </TABLE>
    </TABLES>
    </DATABASE>
    null

    See this thread;
    {thread:id=2180799}
    Jeff

  • Append XML elements with same name in an XML document

    Hi,
    I am using Oracle9i XMLDB utilities to modify an XML document stored in the database. I have a sample XML document like this in the database:
    <Person>
    <Address ID="1"> </Address>
    </Person>
    My task is to include a second <Address> element with a different attribute so that my XML document will become
    <Person>
    <Address ID="1"> </Address>
    <Address ID="2"> </Address>
    </Person>
    After creating the second element, I am using the function xmldom.appendChild() or xmldom.insertBefore() but they remove the first <Address> element and replace it with the second one. This is not what I want since I want both <Address> elements to be present.
    Could anyone please advise.
    Thanks.
    A. Dennis

    Please post your question [url http://forums.oracle.com/forums/forum.jsp?forum=154]here for quick response.
    thank you.
    Regards,
    Anupama
    [url http://otn.oracle.com/sample_code/]OTN Sample Code

  • How to Canonicalize an Big XML?

    Hello, i want to Canonicalize a big XML (like 1GB or more), the program it's in DOM, but dom can't manage big XML documents, so i was thinking to do it with STAX. How i can do it?
    The Code (with dom) that i have it's:
    File file=new File("big-1gb.xml");
    org.apache.xml.security.Init.init();
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = dfactory.newDocumentBuilder();
    Document doc = documentBuilder.parse(file);
    Canonicalizer c14n = Canonicalizer.getInstance("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
    outputBytes = c14n.canonicalizeSubtree(doc.getElementsByTagName("SomeTag").item(0));
    The idea it's do the code below with Stax...
    Thx :)

    yes i'm trying to create a XMLSignature :)
    Well, i solve the problem, here is the solution:
    XOM have an example that use low memory (see nu.xom.samples.MinimalNodeFactory in the source code of XOM), so, i use this code to canonicalize 200Mb XML file:
    ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
    ObjectOutputStream outputstream = new ObjectOutputStream(bytestream);
    nu.xom.Builder builder = new nu.xom.Builder(false, new nu.xom.samples.MinimalNodeFactory()); //The false parameter is for avoid a ValidationException that trows XOM
    try {
         nu.xom.canonical.Canonicalizer outputter = new nu.xom.canonical.Canonicalizer(outputstream);
         nu.xom.Document input = builder.build(file);
         outputter.write(input);
         catch (Exception ex) {
         System.err.println(ex);
         ex.printStackTrace();
    outputstream.close();
    MessageDigest sha1 = MessageDigest.getInstance("SHA1");
    sha1.reset();
    sha1.update(java.nio.ByteBuffer.wrap(bytestream.toByteArray()));
    salidasha1=sha1.digest();
    String tagDigestValue=new String(Base64.encodeBase64(salidasha1));
    /* Rest of digitalsig program */Take like 7 minutes to do the XML signature and the final XML it's like 2Gb :)
    I hope that if some have the same problem can use this :)
    And the final tips: AVOID DOM, with DOM i will need 10x of RAM the size of the XML File (in this case like 20Gb of RAM)
    ps.: Other day i will post how much time take to process 1GB XML Files :)
    Edited by: Enriquesmw on May 7, 2010 12:26 PM

  • Xml Document is not formed correctly.. Help me..

    Using the .xsd files provided to me, I created XMLBeans using the schema project in weblogic 8.1 sp2.
    These XMLBeans are used to create a XML document in my Weblogic Integration process. The values in the xml document are retrieved from a database (which cannot administered/viewed by me). XML document was formed perfectly. But recently when I tried running the application again, I found that the xml is not created properly.
    When I tried to print the xml message, it displays the xml message with the first letter changed from '<' to '<'.
    eg.
    <batch_document>
    </batch_document> is displayed as
    <batch_document>
    </batch_document>
    What may be the reason behind this change. Is it possible because of some invalid data from the backend? If so, what could be the data?
    Is there any special characters which when inserted between the elements makes the document like this?
    The code that creates the xml document looks like this ...
    BatchDocumentDocument bDoc= BatchDocumentDocument.Factory.newInstance();
    BatchDocument bd= bDoc.addNewBatchDocument();
    System.out.println(bDoc.toString());
    The print statement prints the xml message as
    <batch_document>
    </batch_document>
    I would be grateful even if I am answered with any of these questions.
    Thanks in advance.

    Hello Elango,
    Have you tried validating the instance document using the validate() method
    -Raj
    <Elango SV> wrote in message news:[email protected]..
    Using the .xsd files provided to me, I created XMLBeans using the schema
    project in weblogic 8.1 sp2.
    These XMLBeans are used to create a XML document in my Weblogic
    Integration process. The values in the xml document are retrieved from a
    database (which cannot administered/viewed by me). XML document was formed
    perfectly. But recently when I tried running the application again, I
    found that the xml is not created properly.
    When I tried to print the xml message, it displays the xml message with
    the first letter changed from '<' to '<'.
    eg.
    <batch_document>
    </batch_document> is displayed as
    <batch_document>
    </batch_document>
    What may be the reason behind this change. Is it possible because of some
    invalid data from the backend? If so, what could be the data?
    Is there any special characters which when inserted between the elements
    makes the document like this?
    The code that creates the xml document looks like this ...
    BatchDocumentDocument bDoc= BatchDocumentDocument.Factory.newInstance();
    BatchDocument bd= bDoc.addNewBatchDocument();
    System.out.println(bDoc.toString());
    The print statement prints the xml message as
    <batch_document>
    </batch_document>
    I would be grateful even if I am answered with any of these questions.
    Thanks in advance.

  • ISO-8559-1 XML document retrieval

    Can an ISO-8559-1 XML document be stored in a database with a AL32UTF8 character set and then be retrieve ed as an ISO-8559-1 document again?
    if not what need to be done to get the data saved and retrieved as ISO-8559-1.
    Please Help

    By default document will be returned in the characater set requested by the client. Programatically you can use the getBlobVal() method to request a particular character set. I think you can also request a particular character set using XMLSerialize but I'm not sure of the top of my head if this part of the API was implemented / tested / exposed.

  • How to use java to create an XML document from an SQL database?

    Hi,
    I'm a complete novice at XML and have only recently started programming in Java.
    I'm currently trying to develop a package in Java 1.1.8 which requires a set of very specifically formatted XML documents. These documents would need to be updated regularly by people with no knowledge of Java and I would like to make it as simple as possible.
    Since the data will already be in an SQL database, I thought it might be possible to generate the XML documents from the data using a small Java application, but I'm not too sure how to go about this or if this is even possible! Any help or pointers in the right direction would be very much appreciated.
    Louise

    Do you have the option of upgrading to a newer version of the JDK?
    JAXB does what you are wanting very easily. Also there are tools if you don't want to write your own. JAXB is available as early release on Sun's site as is the newest JDK. Otherwise, you have to design a factory and interface that will do this for you (which is what JAXB basically is in a very simplified view).

  • A space in xml-document is stored in database as New line feed instead of n

    Hello,
    I have got the following problem:
    An xml-document is inserted by an xsql servlet into an object view. First this document is translated by an xsl file. Then an instead of trigger inserts the values into the right tables.
    When a space is present (only one space no further string-value) in the xml-document then this space is inserted into the database as a new line feed.(chr(10))
    When I add the following line to the tag
    <bnr_name xml:space="preserve"> </bnr_name>
    then the space is stored as a space. (chr(32))
    What I want is that this space is inserted as a NULL- value.
    Does anyone know a solution in xml or xsl? (Of course I can solve it on the database side by programming a function around it, but I want to solve it on the xml or xsl side)
    Bye
    jan-Paul Duister

    Few questions which might help to understand the issue.
    1. Is client's data is coming in more than 72 chars per each line? Then you can request client to send the data with max. 72 chars per line. Else dividing the string into 72 chars will loose the readability of text since logic can not be built to divide the text.
    Start reading the text string starting from left for maximum 72 chars . If 72th character is non space then go backwards i.e. read 71, 70, 69... till last character should be a SPACE.
    Eg. string is
    'xxxxxxxxxxx...........This material is created for plant xyz. date of creation is 03.02.2009'.
    x = string72(1) should be a SPACE else take x = string71(1)  and likewise.

  • BLOB ibfo into XML document

    Hi forumers,
    I've been asked to build a table to keep some data in XML format. Actually this data resides in a relational table and one of the columns is BLOB.
    Can I store BLOB in a XML document ? (for the other columns I'm using XMLFOREST()).
    If this is possible and if I want to "extract" this BLOB information from XML document how can I do this ?
    Best Regards,
    Helena

    Correction made on the subject

  • XML document convert into String and Insert into Database

    Hello all,
         In the FIle to File Scenario  I want to send the data to the Reciever System in xml Document and convert into String and insert into Database.
      Please can you tell me exact way how to send it.
    Thanks & Regards,
    Raj

    HI,
    As per my understanding your scenario is File to file where you will get output fiel in XML format.
    Now that XMl payload need to be passed as single string in the database via XI.
    You cauld do this but you need to imply some manipulations such as
    With the help of standard API you need to concatenate the  XML tags and create the structre along with the data.
    For e.g. in your outpuf file the XML structre contain data as
    <field1>ABCD</field1>
    Then in mapping
    The source field will be mappeda s concat(<field1>) + value of  Source field "ABCD" + concat(</field1>) to the target field.
    This is the way that you could achive the requirments else there is no direct way avaialble for it.
    thanks
    Swarup

  • Database table updation with XML Document data

    import java.io.*;
    import java.lang.*;
    import java.net.URL;
    import java.sql.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import oracle.xml.sql.dml.OracleXMLSave;
    import org.w3c.dom.Document;
    public class updateXMLData
    public static void main( String argv[] ) throws SQLException,Exception
    String tabName = "emp";
    Connection conn = null;
    String xmlString;
    Document doc;
    URL filename;
    try
    //init a JDBC connection using Oracle's JDBC Drivers
    String host = "maple"; // change,these won't work
    String port = "1521";
    String sid = "PBSI";
    String s1 = "jdbc:oracle:thin:@" + host + ":" + port + ":" + sid;
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection( s1,"scott","tiger");
    // Instructions for updating the database rows from XML Document
    OracleXMLSave sav = new OracleXMLSave(conn,tabName);
    filename = sav.getURL("pbsiempupd.xml");
    sav.setRowTag("EMP");
    String[] tempArr = new String[2];
    tempArr[0]="EMPNO";
    tempArr[1]="ENAME";
    sav.setKeyColumnList(tempArr);
    sav.setUpdateColumnList(tempArr);
    int noRows = sav.updateXML(filename);
    System.out.println("No of rows updated : " + noRows);
    catch (SQLException se)
    System.out.println("An SQL exception has occured ");
    System.out.println("The error code is : " + se.getErrorCode());
    System.out.println("The SQL State is : " + se.getSQLState());
    System.out.println("The message is : " + se.getMessage());
    catch (Exception e)
    System.out.println("Unknown exception has occured");
    System.out.println("The class is : "+ e.getClass());
    System.out.println("The message is : "+e.getMessage());
    finally
    if (conn != null) conn.close();
    The input XML Document is given below :- in 'pbsiempupd.xml'
    <?xml version="1.0"?>
    <ROWSET>
    <EMP>
    <EMPNO>8888</EMPNO>
    <ENAME>RAO THOTAKURA</ENAME>
    </EMP>
    <EMP>
    <EMPNO>9999</EMPNO>
    <ENAME>BAVA MANI</ENAME>
    </EMP>
    <EMP>
    <EMPNO>7777</EMPNO>
    <ENAME>SRINIVAS M</ENAME>
    </EMP>
    </ROWSET>
    After executing this class with 'java updataXMLData' I'm getting following runtime error message :-
    Unknown exception has occured
    The class is : class oracle.xml.sql.OracleXMLSQLException
    The message is : Exception 'java.sql.SQLException:Missing IN or OUT parameter at index:: 1'
    encountered during processing ROW element 0All prior XML row changes were rolled back.
    in the XML document.
    Please anybody could explain how to solve it.
    Thanks
    Sambasivarao Thotakura

    See my reply to your other question. thanks.

  • Exception when inserting a XML document into database

    Hello.
    I'm trying to insert the content of a XML document into a database. The problem consists on the exception that is raised when a FK in the XML is not in the database as a PK
    How can i catch these exceptions and continuing inserting the rest of the data
    Thanks in advance ...

    I really hope for you this wasn't a production database, as mentioned in the URL, it has been some years ago for me fiddling around this which was btw a supported metalink workaround ONCE (during my Oracle 7 days), but now, I wouldn't be surprised if you now have mixed NLS content in your tables/database and more or less "corrupted" your content.
    The initial issue was probably a client one.
    BTW
    I actually hope it was a production database, maybe then you would learn that way, that you SHOULD NEVER EVER UPDATE DATABASE BASE TABLES directly...
    ...unless (the only exception) you want to learn something about the internals and don't care that your TEST database gets corrupted....

  • XML download from blob

    Hi
    I have a table which has blob column which is xml file. I need to extract xml file and store to local desktop.
    Please help me.
    Thanks
    Ranga

    This example generates some XML into an XMLTYPE, turns it into a BLOB and then saves it out to file...
    DECLARE
       -- Data Variables
       v_xml              XMLTYPE;
       v_blob             BLOB;
       v_data_length      NUMBER;
       -- Loop Control Variables
       v_offset           NUMBER             DEFAULT 1;
       v_chunk   CONSTANT NUMBER             DEFAULT 4000;
       -- UTL_FILE variables
       fh                 UTL_FILE.file_type;
    BEGIN
       -- A big query, about 27k on my PC
       SELECT XMLELEMENT ("Employees", XMLAGG (emp_dept))
         INTO v_xml
         FROM (SELECT XMLELEMENT
                         ("Employee",
                          XMLFOREST
                             (e.employee_id AS "EmployeeId",
                              e.last_name AS "Name",
                              e.job_id AS "Job",
                              e.manager_id AS "Manager",
                              e.hire_date AS "HireDate",
                              e.salary AS "Salary",
                              e.commission_pct AS "Commission",
                              XMLFOREST (d.department_id AS "DeptNo",
                                         d.department_name AS "DeptName",
                                         d.location_id AS "Location"
                                        ) AS "Dept"
                         ) emp_dept
                 FROM employees e, departments d
                WHERE e.department_id = d.department_id);
       -- Turn the XML into a BLOB to bypass any 4k and 32k issues
       v_blob := v_xml.getblobval (1);
       v_data_length := DBMS_LOB.getlength (v_blob);
       -- Open the file
       fh := UTL_FILE.fopen ('XML_FILES', 'myxml.xml', 'wb', v_chunk);
       -- Da loop de loop
       LOOP
          -- Exit when our file offset is bigger than our file
          EXIT WHEN v_offset > v_data_length;
          -- Write the output chunk by chunk
          UTL_FILE.put_raw (fh, DBMS_LOB.SUBSTR (v_blob, v_chunk, v_offset),
                            TRUE);
          -- Increment the offset by the amount written
          v_offset := v_offset + v_chunk;
       END LOOP;
       -- Close the file and say byebye
       UTL_FILE.fclose (fh);
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          -- We won't write any data, or even open the file,
          -- if the query return no rows
          NULL;
    END;This next example simply queries a CLOB from the database and saves it to file...
    DECLARE
      l_file    UTL_FILE.FILE_TYPE;
      l_clob    CLOB;
      l_buffer  VARCHAR2(32767);
      l_amount  BINARY_INTEGER := 32767;
      l_pos     INTEGER := 1;
    BEGIN
      SELECT col1
      INTO   l_clob
      FROM   tab1
      WHERE  rownum = 1;
      l_file := UTL_FILE.fopen('DOCUMENTS', 'Sample2.txt', 'w', 32767);
      LOOP
        DBMS_LOB.read (l_clob, l_amount, l_pos, l_buffer);
        UTL_FILE.put(l_file, l_buffer);
        l_pos := l_pos + l_amount;
      END LOOP;
    EXCEPTION
      WHEN OTHERS THEN
        DBMS_OUTPUT.put_line(SQLERRM);
        UTL_FILE.fclose(l_file);
    END;The process will always finish with a NO_DATA_FOUND exception when the end of the CLOB is reached. For simplicity I've not trapped any of the possible UTL_FILE exceptions.
    For details on using UTL_FILE...
    http://www.psoug.org/reference/utl_file.html

  • Help - Inserting an XML document into a Oracle 8i Column (CLOB Type)

    Hi JavaGurus,
    I am looking for a simple java code which will take my XML document as input and insert the same into a Oracle 8i database's column which is of type CLOB.
    Insert statement won't work and I can not use SQL Loader.
    Any one?
    JK

    Maybe you can adapt some of the code in Oracle's "LOB Datatype" example, which is a complete working program that stores and retrieves BLOBs and CLOBs.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.html

Maybe you are looking for