You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "kishorevodnala (JIRA)" <ji...@apache.org> on 2006/11/10 07:11:37 UTC

[jira] Created: (DERBY-2070) Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby

Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby
------------------------------------------------------------------------------------------

                 Key: DERBY-2070
                 URL: http://issues.apache.org/jira/browse/DERBY-2070
             Project: Derby
          Issue Type: Bug
         Environment: Windows 98,Derby ,JAVA.
            Reporter: kishorevodnala


I have a problem while inserting an XML document object into a BLOB column in Derby database.

Could you please help me out in resolving this problem.

Note:there is empty_blob function in oracle for initialising a BLOB.Is there anything in derby for initialising a BLOB like in oracle.

Following is the sample code.
//creating a DOM object for a xml file and storing this object into the BLOB column in the database using streams.

class exdom
{
	public static void main(String ss[])
	{
		Document pdxDOM =buildDocument();//creating a DOM object for xml file
		serializePDXDOMToDB(pdxDOM); //storing this object into the BLOB column in the database using  streams 
	}

     public static Document buildDocument() {
        Document document = null;
        try {
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
            document = documentBuilder.parse(new File("d:\\sample.xml"));

        }  catch (Exception e) {e.printStackTrace();}
            
        return document;
    }


	 public static void serializePDXDOMToDB(Document obj) {
        Connection conn = null;
    	        PreparedStatement ps = null;
        ResultSet rs = null;
        String query = "insert into ex9(bl) values(?) " ;
        
        try {
        	Class.forName("org.apache.derby.jdbc.ClientDriver");
			String url="jdbc:derby://s104f50:1527/example;create=true";
			 conn=DriverManager.getConnection(url);
        	 
	            ps = conn.prepareStatement(query);
	            ByteArrayOutputStream baos = new ByteArrayOutputStream();
	            ObjectOutputStream oout = new ObjectOutputStream(baos);
	            oout.writeObject(obj);
	            oout.close();
	            
	            ps.setBytes(1, baos.toByteArray());
	            ps.execute();
	             
                
			
		}catch(Exception e){e.printStackTrace();}
	 }
}
 



Following is the exception that occured while execution:

java.io.NotSerializableException: org.apache.crimson.tree.XmlDocument
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)

        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java
:1330)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:13
02)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.jav
a:1245)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
        at exdom.serializePDXDOMToDB(exdom.java:42)
        at exdom.main(exdom.java:11)

//this code is working fine for String and Integer objects but getting an Exception while trying to insert an XML Document object.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (DERBY-2070) Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby

Posted by "Andrew McIntyre (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-2070?page=all ]

Andrew McIntyre resolved DERBY-2070.
------------------------------------

    Resolution: Invalid

JIRA should be used to file bugs or request features. Please use the derby-user mailing list for general questions about Derby. For information on using the Derby mailing lists, see: http://db.apache.org/derby/derby_mail.html

> Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby
> ------------------------------------------------------------------------------------------
>
>                 Key: DERBY-2070
>                 URL: http://issues.apache.org/jira/browse/DERBY-2070
>             Project: Derby
>          Issue Type: Bug
>         Environment: Windows 98,Derby ,JAVA.
>            Reporter: kishorevodnala
>
> I have a problem while inserting an XML document object into a BLOB column in Derby database.
> Could you please help me out in resolving this problem.
> Note:there is empty_blob function in oracle for initialising a BLOB.Is there anything in derby for initialising a BLOB like in oracle.
> Following is the sample code.
> //creating a DOM object for a xml file and storing this object into the BLOB column in the database using streams.
> class exdom
> {
> 	public static void main(String ss[])
> 	{
> 		Document pdxDOM =buildDocument();//creating a DOM object for xml file
> 		serializePDXDOMToDB(pdxDOM); //storing this object into the BLOB column in the database using  streams 
> 	}
>      public static Document buildDocument() {
>         Document document = null;
>         try {
>             DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
>             DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
>             document = documentBuilder.parse(new File("d:\\sample.xml"));
>         }  catch (Exception e) {e.printStackTrace();}
>             
>         return document;
>     }
> 	 public static void serializePDXDOMToDB(Document obj) {
>         Connection conn = null;
>     	        PreparedStatement ps = null;
>         ResultSet rs = null;
>         String query = "insert into ex9(bl) values(?) " ;
>         
>         try {
>         	Class.forName("org.apache.derby.jdbc.ClientDriver");
> 			String url="jdbc:derby://s104f50:1527/example;create=true";
> 			 conn=DriverManager.getConnection(url);
>         	 
> 	            ps = conn.prepareStatement(query);
> 	            ByteArrayOutputStream baos = new ByteArrayOutputStream();
> 	            ObjectOutputStream oout = new ObjectOutputStream(baos);
> 	            oout.writeObject(obj);
> 	            oout.close();
> 	            
> 	            ps.setBytes(1, baos.toByteArray());
> 	            ps.execute();
> 	             
>                 
> 			
> 		}catch(Exception e){e.printStackTrace();}
> 	 }
> }
>  
> Following is the exception that occured while execution:
> java.io.NotSerializableException: org.apache.crimson.tree.XmlDocument
>         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
>         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java
> :1330)
>         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:13
> 02)
>         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.jav
> a:1245)
>         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
>         at exdom.serializePDXDOMToDB(exdom.java:42)
>         at exdom.main(exdom.java:11)
> //this code is working fine for String and Integer objects but getting an Exception while trying to insert an XML Document object.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DERBY-2070) Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby

Posted by "Anurag Shekhar (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-2070?page=comments#action_12448705 ] 
            
Anurag Shekhar commented on DERBY-2070:
---------------------------------------

org.w3c.dom.Document doesn't extends from Serializable so it can't be written into stream unless the implementation class is extending from the same. In case of Crimson the implementation doesn't appears to be be extending from it either. Hence the java.io.NotSerializableException.

So you may have to either insert the XML file as text stream into blob or clob fields. If you are using derby 10.2 you can look into XML data type and functions related to that to see if it meets your requirements.
here is the link of ref. manual if you want to know more about XML functions available in derby

http://db.apache.org/derby/docs/10.2/ref/

> Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby
> ------------------------------------------------------------------------------------------
>
>                 Key: DERBY-2070
>                 URL: http://issues.apache.org/jira/browse/DERBY-2070
>             Project: Derby
>          Issue Type: Bug
>         Environment: Windows 98,Derby ,JAVA.
>            Reporter: kishorevodnala
>
> I have a problem while inserting an XML document object into a BLOB column in Derby database.
> Could you please help me out in resolving this problem.
> Note:there is empty_blob function in oracle for initialising a BLOB.Is there anything in derby for initialising a BLOB like in oracle.
> Following is the sample code.
> //creating a DOM object for a xml file and storing this object into the BLOB column in the database using streams.
> class exdom
> {
> 	public static void main(String ss[])
> 	{
> 		Document pdxDOM =buildDocument();//creating a DOM object for xml file
> 		serializePDXDOMToDB(pdxDOM); //storing this object into the BLOB column in the database using  streams 
> 	}
>      public static Document buildDocument() {
>         Document document = null;
>         try {
>             DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
>             DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
>             document = documentBuilder.parse(new File("d:\\sample.xml"));
>         }  catch (Exception e) {e.printStackTrace();}
>             
>         return document;
>     }
> 	 public static void serializePDXDOMToDB(Document obj) {
>         Connection conn = null;
>     	        PreparedStatement ps = null;
>         ResultSet rs = null;
>         String query = "insert into ex9(bl) values(?) " ;
>         
>         try {
>         	Class.forName("org.apache.derby.jdbc.ClientDriver");
> 			String url="jdbc:derby://s104f50:1527/example;create=true";
> 			 conn=DriverManager.getConnection(url);
>         	 
> 	            ps = conn.prepareStatement(query);
> 	            ByteArrayOutputStream baos = new ByteArrayOutputStream();
> 	            ObjectOutputStream oout = new ObjectOutputStream(baos);
> 	            oout.writeObject(obj);
> 	            oout.close();
> 	            
> 	            ps.setBytes(1, baos.toByteArray());
> 	            ps.execute();
> 	             
>                 
> 			
> 		}catch(Exception e){e.printStackTrace();}
> 	 }
> }
>  
> Following is the exception that occured while execution:
> java.io.NotSerializableException: org.apache.crimson.tree.XmlDocument
>         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
>         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java
> :1330)
>         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:13
> 02)
>         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.jav
> a:1245)
>         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
>         at exdom.serializePDXDOMToDB(exdom.java:42)
>         at exdom.main(exdom.java:11)
> //this code is working fine for String and Integer objects but getting an Exception while trying to insert an XML Document object.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DERBY-2070) Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby

Posted by "kishorevodnala (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-2070?page=comments#action_12449195 ] 
            
kishorevodnala commented on DERBY-2070:
---------------------------------------


Hi Anurag,

Many thanks for your quick response.
Please see the following code.here i made Document object as serializable.even then it is giving the same Exception.

class SerialPDX implements Serializable {
    public Document PDXDoc;
    public SerialPDX(Document PDXDoc) {
        this.PDXDoc = PDXDoc;
    }
}

SerialPDX serializedPDXDocument = new SerialPDX(obj);//here converting document object as a serializable object.
									//obj is a document object.


Also please let me confirm that is there any way to initialise BLOB in derby like in Oracle.


Thanks with Regards
Kishore Vodnala




> Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby
> ------------------------------------------------------------------------------------------
>
>                 Key: DERBY-2070
>                 URL: http://issues.apache.org/jira/browse/DERBY-2070
>             Project: Derby
>          Issue Type: Bug
>         Environment: Windows 98,Derby ,JAVA.
>            Reporter: kishorevodnala
>
> I have a problem while inserting an XML document object into a BLOB column in Derby database.
> Could you please help me out in resolving this problem.
> Note:there is empty_blob function in oracle for initialising a BLOB.Is there anything in derby for initialising a BLOB like in oracle.
> Following is the sample code.
> //creating a DOM object for a xml file and storing this object into the BLOB column in the database using streams.
> class exdom
> {
> 	public static void main(String ss[])
> 	{
> 		Document pdxDOM =buildDocument();//creating a DOM object for xml file
> 		serializePDXDOMToDB(pdxDOM); //storing this object into the BLOB column in the database using  streams 
> 	}
>      public static Document buildDocument() {
>         Document document = null;
>         try {
>             DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
>             DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
>             document = documentBuilder.parse(new File("d:\\sample.xml"));
>         }  catch (Exception e) {e.printStackTrace();}
>             
>         return document;
>     }
> 	 public static void serializePDXDOMToDB(Document obj) {
>         Connection conn = null;
>     	        PreparedStatement ps = null;
>         ResultSet rs = null;
>         String query = "insert into ex9(bl) values(?) " ;
>         
>         try {
>         	Class.forName("org.apache.derby.jdbc.ClientDriver");
> 			String url="jdbc:derby://s104f50:1527/example;create=true";
> 			 conn=DriverManager.getConnection(url);
>         	 
> 	            ps = conn.prepareStatement(query);
> 	            ByteArrayOutputStream baos = new ByteArrayOutputStream();
> 	            ObjectOutputStream oout = new ObjectOutputStream(baos);
> 	            oout.writeObject(obj);
> 	            oout.close();
> 	            
> 	            ps.setBytes(1, baos.toByteArray());
> 	            ps.execute();
> 	             
>                 
> 			
> 		}catch(Exception e){e.printStackTrace();}
> 	 }
> }
>  
> Following is the exception that occured while execution:
> java.io.NotSerializableException: org.apache.crimson.tree.XmlDocument
>         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
>         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java
> :1330)
>         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:13
> 02)
>         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.jav
> a:1245)
>         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
>         at exdom.serializePDXDOMToDB(exdom.java:42)
>         at exdom.main(exdom.java:11)
> //this code is working fine for String and Integer objects but getting an Exception while trying to insert an XML Document object.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira