Link to home
Start Free TrialLog in
Avatar of AnnaBZ
AnnaBZ

asked on

JDBC :problem in storing content of svg file into Oracle xmltype column

HI ,guys
I'm trying to insert content of SVG file into xmltype column in Oracle DB
I must insert it into xmltype column
but after executing the  pstmt.executeUpdate();
it jumps to exception and I get something like this:  
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00256: invalid element
I soppose  I do it wrong way ,do somebody knows how to insert svg file content
 to xmltype column  
Thanks in advance

create table AD_ASSETS_CONTENTS_CHAR (CONTENT_SVG xmltype);
(all *.svg  files are in utf-8 format )

try
{
 String query ="Insert into AD_ASSETS_CONTENTS_CHAR "+
               "(CONTENT_SVG) values (xmltype(?)) ";

                File f = new File ( "c:/test/350.svg" );
                InputStream in = new FileInputStream(f);


              PreparedStatement pstmt = connection.prepareStatement(query);
              pstmt.setAsciiStream(1,in,in.available());    
              pstmt.executeUpdate();
              pstmt.close();
}
      catch (Exception e)
      {
                  e.printStackTrace();  
      }







Avatar of girionis
girionis
Flag of Greece image

> ORA-31011: XML parsing failed

  THis actually indicates a failure in parsing. Can you make sure your XML is well formed and valid?
Avatar of grim_toaster
grim_toaster

I've had a go at using your code to put a very simple XML document into the database, and it worked fine.  I would suggest running you SVG document through an XML validator to ensure that it is valid.  Also, it might help if you post your SVG file.

Try a simple XML document, (i.e. <test><does><it><work /></it></does></test>), and see if that works.
> LPX-00256: invalid element

  This probably indicates the problem.
I knew I should have commented when I first read the question ;-)

I was going to say that it looked like the XML was not well formed and/or valid and that LPX-00256 was probably the root cause.

I didn't bother because I wasn't sure what format SVG was :-(

Maybe next time ;-)
 jimmack, be fast or be last :)
The problem seems to be that as soon as objects goes to sleep, girionis wakes up.  When you go away, CEHJ pops up.
;-)

At least I now know that SVG is XML ;-)
 Hehe :) Not strictly true... Lately I can't participate as much as I used to do... I mainly clean abandoned questions now :)
Ah.  Perhaps that's why I've managed to pick up some points between the binary black holes of objects and CEHJ then ;-)

TimYates is another one.  Wasn't he panicking recently, 'cos you were catching up? ;-)
Avatar of AnnaBZ

ASKER

This is an SVG file grim_toaster , it is bigger then 4000 characters so I cannot use String

<?xml version = '1.0' encoding = 'utf-8'?>
<!-- Generator: Adobe Illustrator 10.0, SVG Export Plug-In . SVG Version: 3.0.0 Build 76)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
<!ENTITY ns_svg "http://www.w3.org/2000/svg">
<!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
]>
<?AdobeSVGViewer save="snapshot"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" width="179.0" height="63.62399673461914" viewBox="0 0 179.0 63.62399673461914" overflow="visible" enable-background="new 0 0 179.0 63.62399673461914" xml:space="preserve">
     <style type="text/css">
   
                @font-face{font-family:'AvantGarde-Demi';src:url(../../../fonts/A746586D.cef)}
   
                @font-face{font-family:'AINarkissTam-Medium';src:url(../../../fonts/6F2751A9.cef)}
   
                @font-face{font-family:'AINarkisTamB';src:url(../../../fonts/63027B3C.cef)}
   
                @font-face{font-family:'AIKislev';src:url(../../../fonts/96084A9E.cef)}
   
                @font-face{font-family:'Grafitti';src:url(../../../fonts/7A6FFD77.cef)}
   
                @font-face{font-family:'ZapfDingbats';src:url(../../../fonts/90A2E2BB.cef)}
     </style>
     <g id="MM1">
        <g id="framepath">
           <path fill="#ffffff" stroke="#000000" stroke-miterlimit="10" d="M48.165,12.333330631256104H0v55.290665h179.0V14.333330631256104"/>
        </g>
        <metadata ad_id="498" obj_type="&#1502;&#1502;1" ad_price="556" sort_key="116900" text_sort_key="&#1505;&#1504;&#1492; &#1500;&#1506;&#1489; &#1505;&#1489;&#1490;" obj_fam="2" cust_id="69366600" cust_sort="#cust_sort" book="52" year="2003" class_id="25410" class_name="PARTITIONS - PLASTER" framewidth="179.0" align="right" indent-left="0" indent-right="0" language="HE" direct="rtl"/>
        <g id="freetext">
           <g id="freetext1"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 12.869995 59.45733022689819)" style="font-family:'AvantGarde-Demi'; font-size:12.5; fill:#00ff00">1234-567</text>
              <text id="freetext" transform="matrix(0.74 0 0 1 67.895 59.45733022689819)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#0000ff">±°¯· àøâ ïá ãåäà úâ úéø÷</text>
           </g>
           <g id="freetext2"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 9.817505 44.99883031845093)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">°µ¶­·¶´´´°</text>
              <text id="freetext" transform="matrix(0.74 0 0 1 64.84251 44.99883031845093)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">íéììë íéöåôéùå òáö úåãåáò</text>
           </g>
           <g id="freetext3"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.765625 0 0 1 13.917503 29.290831089019775)" style="font-family:&#39;AINarkisTamB&#39;; font-size:16.0; fill:#ff0000">ñáâ úåöéçî ¬úåéèñå÷à úåø÷ú</text>
           </g>
        </g>
        <g id="Businessname">
           <g id="BusinessName4"><metadata align="right" indent-left="0.0" indent-right="0.0"/>
              <text transform="matrix(0.74 0 0 1 51.165 12.333330631256104)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">ïäã óñåé ­ ¢ñðä ìòá ñá⢠­ ã¢ñá</text>
           </g>
        </g>
     </g>
</svg>
> This is an SVG file grim_toaster , it is bigger then 4000 characters so I cannot use String

  Why don't you load it up in an XML editor and validate it?

  jimmack:

> TimYates is another one.

  Yeap and he has already left me behind... I need to work harder :)
> Yeap and he has already left me behind... I need to work harder :)

Hee hee, or "work" less hard, and EE more ;-)  *giggle*
> or "work" less hard, and EE more

  Heheh Tim, so true :)
Avatar of AnnaBZ

ASKER

Why don't you load it up in an XML editor and validate it?

Guy's , I'm quite new in Java and Xml  and here too ,so I don't know how to use XML editor,
But my code (upper ) works if I pass is a simple xml string , but my file bigger then 4000,
so I cannot pass it as string  and that is why I use  pstmt.setAsciiStream(..,..,..)
Maybe here should be something else?
 If the size of xmltype column is limited you might need to use a BLOB or CLOB type.
My XML isn't that strong, so I'm not sure if this is going to help or hinder, but my XML editor complained about the file you posted:

Error while parsing XML: Cannot create entity declaration in document type declaration

This appears to be a problem with the line at the top of the file that begins:

<!ENTITY ns_flows ...

 Look here:

http://edocs.bea.com/wls/docs81/jdbc_drivers/oracle.html

  An Oracle XMLTYPE is a CLOB jdbc type.
Avatar of AnnaBZ

ASKER

no the size of xmltype column is not limited and I must use xmltype column and not BLOB or CLOB type.
And I'm sure that there is no problem with a svg file ,because i cal view it throw Enternet Explorer

I looked here girionis
 http://edocs.bea.com/wls/docs81/jdbc_drivers/oracle.html
And it works greate ,but with string , which I can't use
Am I missing something here?  As far as I can tell, XMLTYPE isn't an SQL column type.
 Right, lets elimitae possible causes first.

  Can you make sure that this line:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG- 20010904/DTD/svg10.dtd"

  is as follows:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"

  Please eliminate the space between SVG- and 20010904 and try again.
> As far as I can tell, XMLTYPE isn't an SQL column type.

  This type only exists in Oracle 9i and correlates to CLOB in JDBC types.
>> This type only exists in Oracle 9i and correlates to CLOB in JDBC types.

Bingo.  Goal for the day achieved.  I learned something new and potentially useful ;-)
Here's something to try, to find out what area the problem is in, whether it is the database formatting, or the way the xml document is transfered, might I suggest running the insert script directly into your Oracle database (via SQLPlus).

Put the following into a script file and run it, and just to check, you do have internet access from the machines involved to resolve the external references???

INSERT INTO AD_ASSETS_CONTENTS_CHAR VALUES (XMLType.CreateXML('<?xml version = "1.0" encoding =
<!-- Generator: Adobe Illustrator 10.0, SVG Export Plug-In . SVG Version: 3.0.0 Build 76)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
<!ENTITY ns_svg "http://www.w3.org/2000/svg">
<!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
]>
<?AdobeSVGViewer save="snapshot"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="htt
     <style TYPE="text/css">
                @font-face{font-family:"AvantGarde-Demi";src:url(../../../fonts/A746586D.cef)}
                @font-face{font-family:"AINarkissTam-Medium";src:url(../../../fonts/6F2751A9.cef)}
                @font-face{font-family:"AINarkisTamB";src:url(../../../fonts/63027B3C.cef)}
                @font-face{font-family:"AIKislev";src:url(../../../fonts/96084A9E.cef)}
                @font-face{font-family:"Grafitti";src:url(../../../fonts/7A6FFD77.cef)}
                @font-face{font-family:"ZapfDingbats";src:url(../../../fonts/90A2E2BB.cef)}
     </style>
     <g id="MM1">
        <g id="framepath">
           <path fill="#ffffff" stroke="#000000" stroke-miterlimit="10" d="M48.165,12.333330631256104H0v55
        </g>
        <metadata ad_id="498" obj_type="&#1502;&#1502;1" ad_price="556" sort_key="116900" text_sort
        <g id="freetext">
           <g id="freetext1"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 12.869995 59.45733022689819)" style="font-f
              <text id="freetext" transform="matrix(0.74 0 0 1 67.895 59.45733022689819)" style="font-fami
           </g>
           <g id="freetext2"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 9.817505 44.99883031845093)" style="font-fa
              <text id="freetext" transform="matrix(0.74 0 0 1 64.84251 44.99883031845093)" style="font-fa
           </g>
           <g id="freetext3"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.765625 0 0 1 13.917503 29.290831089019775)" style="f
           </g>
        </g>
        <g id="Businessname">
           <g id="BusinessName4"><metadata align="right" indent-left="0.0" indent-right="0.0"/>
              <text transform="matrix(0.74 0 0 1 51.165 12.333330631256104)" style="font-family:&#39;AINar
           </g>
        </g>
     </g>
</svg>
'))
 It is complaining for the "ad_id" attribute in the "metadata" tag. Check if this attribute is valid.

  Also it is complaining for the closing tag "</ text>" of the <text id="freetext" transform="matrix(0.74 0 0 1 9.817505 44.99883031845093)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000"> (note the space between the "/" symbol and "text")

  And it is also complaining for the space at the end (between "/" and ">") of the following line:

<metadata align="right" indent-left="0.0" indent-right="0.0"/ >

  Please correct the last two problems first and then the first one and try again.
Oops, sorry, my update query should have read as below (truncated by SQLPlus), your document seems well formed, but I am unable to test myself as my database does not allow some of those characters, but the concept should (but I did try after removing them, and it worked!)!:

INSERT INTO AD_ASSETS_CONTENTS_CHAR VALUES (XMLType.CreateXML('<?xml version="1.0" encoding="UTF-8"?>
<!-- Generator: Adobe Illustrator 10.0, SVG Export Plug-In . SVG Version: 3.0.0 Build 76)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
<!ENTITY ns_svg "http://www.w3.org/2000/svg">
<!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
]>
<?AdobeSVGViewer save="snapshot"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" width="179.0" height="63.62399673461914" viewBox="0 0 179.0 63.62399673461914" overflow="visible" enable-background="new 0 0 179.0 63.62399673461914" xml:space="preserve">
     <style type="text/css">
   
                @font-face{font-family:"AvantGarde-Demi";src:url(../../../fonts/A746586D.cef)}
   
                @font-face{font-family:"AINarkissTam-Medium";src:url(../../../fonts/6F2751A9.cef)}
   
                @font-face{font-family:"AINarkisTamB";src:url(../../../fonts/63027B3C.cef)}
   
                @font-face{font-family:"AIKislev";src:url(../../../fonts/96084A9E.cef)}
   
                @font-face{font-family:"Grafitti";src:url(../../../fonts/7A6FFD77.cef)}
   
                @font-face{font-family:"ZapfDingbats";src:url(../../../fonts/90A2E2BB.cef)}
     </style>
     <g id="MM1">
        <g id="framepath">
           <path fill="#ffffff" stroke="#000000" stroke-miterlimit="10" d="M48.165,12.333330631256104H0v55.290665h179.0V14.333330631256104"/>
        </g>
        <metadata ad_id="498" obj_type="&#1502;&#1502;1" ad_price="556" sort_key="116900" text_sort_key="&#1505;&#1504;&#1492; &#1500;&#1506;&#1489; &#1505;&#1489;&#1490;" obj_fam="2" cust_id="69366600" cust_sort="#cust_sort" book="52" year="2003" class_id="25410" class_name="PARTITIONS - PLASTER" framewidth="179.0" align="right" indent-left="0" indent-right="0" LANGUAGE="HE" direct="rtl"/>
        <g id="freetext">
           <g id="freetext1"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 12.869995 59.45733022689819)" style="font-family:"AvantGarde-Demi"; font-size:12.5; fill:#00ff00">1234-567</text>
              <text id="freetext" transform="matrix(0.74 0 0 1 67.895 59.45733022689819)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#0000ff">±°¯· àøâ ïá ãåäà úâ úéø÷</text>
           </g>
           <g id="freetext2"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 9.817505 44.99883031845093)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">°µ¶­·¶´´´°</text>
              <text id="freetext" transform="matrix(0.74 0 0 1 64.84251 44.99883031845093)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">íéììë íéöåôéùå òáö úåãåáò</text>
           </g>
           <g id="freetext3"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.765625 0 0 1 13.917503 29.290831089019775)" style="font-family:&#39;AINarkisTamB&#39;; font-size:16.0; fill:#ff0000">ñáâ úåöéçî ¬úåéèñå÷à úåø÷ú</text>
           </g>
        </g>
        <g id="Businessname">
           <g id="BusinessName4"><metadata align="right" indent-left="0.0" indent-right="0.0"/>
              <text transform="matrix(0.74 0 0 1 51.165 12.333330631256104)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">ïäã óñåé ­ ¢ñðä ìòá ñá⢠­ ã¢ñá</text>
           </g>
        </g>
     </g>
</svg>'))


SQLPlus INSERT INTO AD_ASSETS_CONTENTS_CHAR VALUES (XMLType.CreateXML('<?xml version="1.0" encoding="UTF-8"?>
<!-- Generator: Adobe Illustrator 10.0, SVG Export Plug-In . SVG Version: 3.0.0 Build 76)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
<!ENTITY ns_svg "http://www.w3.org/2000/svg">
<!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
]>
<?AdobeSVGViewer save="snapshot"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" width="179.0" height="63.62399673461914" viewBox="0 0 179.0 63.62399673461914" overflow="visible" enable-background="new 0 0 179.0 63.62399673461914" xml:space="preserve">
     <style type="text/css">
   
                @font-face{font-family:"AvantGarde-Demi";src:url(../../../fonts/A746586D.cef)}
   
                @font-face{font-family:"AINarkissTam-Medium";src:url(../../../fonts/6F2751A9.cef)}
   
                @font-face{font-family:"AINarkisTamB";src:url(../../../fonts/63027B3C.cef)}
   
                @font-face{font-family:"AIKislev";src:url(../../../fonts/96084A9E.cef)}
   
                @font-face{font-family:"Grafitti";src:url(../../../fonts/7A6FFD77.cef)}
   
                @font-face{font-family:"ZapfDingbats";src:url(../../../fonts/90A2E2BB.cef)}
     </style>
     <g id="MM1">
        <g id="framepath">
           <path fill="#ffffff" stroke="#000000" stroke-miterlimit="10" d="M48.165,12.333330631256104H0v55.290665h179.0V14.333330631256104"/>
        </g>
        <metadata ad_id="498" obj_type="&#1502;&#1502;1" ad_price="556" sort_key="116900" text_sort_key="&#1505;&#1504;&#1492; &#1500;&#1506;&#1489; &#1505;&#1489;&#1490;" obj_fam="2" cust_id="69366600" cust_sort="#cust_sort" book="52" year="2003" class_id="25410" class_name="PARTITIONS - PLASTER" framewidth="179.0" align="right" indent-left="0" indent-right="0" LANGUAGE="HE" direct="rtl"/>
        <g id="freetext">
           <g id="freetext1"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 12.869995 59.45733022689819)" style="font-family:"AvantGarde-Demi"; font-size:12.5; fill:#00ff00">1234-567</text>
              <text id="freetext" transform="matrix(0.74 0 0 1 67.895 59.45733022689819)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#0000ff">±°¯· àøâ ïá ãåäà úâ úéø÷</text>
           </g>
           <g id="freetext2"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.74 0 0 1 9.817505 44.99883031845093)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">°µ¶­·¶´´´°</text>
              <text id="freetext" transform="matrix(0.74 0 0 1 64.84251 44.99883031845093)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">íéììë íéöåôéùå òáö úåãåáò</text>
           </g>
           <g id="freetext3"><metadata align="center" indent-left="3.0" indent-right="3.0"/>
              <text id="freetext" transform="matrix(0.765625 0 0 1 13.917503 29.290831089019775)" style="font-family:&#39;AINarkisTamB&#39;; font-size:16.0; fill:#ff0000">ñáâ úåöéçî ¬úåéèñå÷à úåø÷ú</text>
           </g>
        </g>
        <g id="Businessname">
           <g id="BusinessName4"><metadata align="right" indent-left="0.0" indent-right="0.0"/>
              <text transform="matrix(0.74 0 0 1 51.165 12.333330631256104)" style="font-family:&#39;AINarkisTamB&#39;; font-size:12.5; fill:#000000">ïäã óñåé ­ ¢ñðä ìòá ñá⢠­ ã¢ñá</text>
           </g>
        </g>
     </g>
</svg>'))
Avatar of AnnaBZ

ASKER

hi grim_toaster
I tried this  INSERT INTO AD_ASSETS_CONTENTS_CHAR VALUES (XMLType.CreateXML('<?xml............................ ,
  still doesn't work
I think because content of the file, on simple xml it works perfectly
probably there is need for  something else for svg be inserted into xmltype column
Just checking you did use the last one I posted?  What error were you getting from Oracle?  Which encoding is the database and SQLPlus session set up for?
Avatar of AnnaBZ

ASKER

The same error:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00256: invalid element

this is the encoding encoding AL32UTF8
Avatar of AnnaBZ

ASKER

Thanks every body
I found the problem , it was in svg file itself :
if I remove this from the file:
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
<!ENTITY ns_svg "http://www.w3.org/2000/svg">
<!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
]>
it works ,it just doesn't know this character  "]>"
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow, when I included those parts on my database it worked fine!  Strange...

It complained about unrecognised characters, but I don't have a the same character set set up, so removing just them (part of one of your metadata tags, and a couple of errors elsewhere)

Glad you sorted it though!