db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "kishorevodnala (JIRA)" <j...@apache.org>
Subject [jira] Created: (DERBY-2070) Is there a way to initialise a BLOB in derby, and how to insert a document object in Derby
Date Fri, 10 Nov 2006 06:11:37 GMT
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 {
			String url="jdbc:derby://s104f50:1527/example;create=true";
	            ps = conn.prepareStatement(query);
	            ByteArrayOutputStream baos = new ByteArrayOutputStream();
	            ObjectOutputStream oout = new ObjectOutputStream(baos);
	            ps.setBytes(1, baos.toByteArray());
		}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
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:13
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.jav
        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


View raw message