db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jay _ <iwud...@hotmail.com>
Subject Saving XML into a database
Date Fri, 22 Aug 2008 18:46:14 GMT

I've been struggling to find some decent examples of how to save XML into a Derby database.

I've managed to figure out that XML needs to be serialised into a different datatype before
it can saved in Derby. I am using a CLOB. However, I am not quite sure how exactly to get
the data into the XML column.

My sample code looks like this .... 

        String expression = "INSERT INTO XML_DATA (DOCUMENT ) " +
                "VALUES (XMLPARSE( DOCUMENT CAST (? AS CLOB) PRESERVE WHITESPACE))";

        try
        {
            PreparedStatement preparedStatement = connection.prepareStatement(expression);
            // update statement and execute
//            Element ele = getHomeViewElement();
            logger.debug("xmlDocument = " + xmlDocument.getDocument().toString());
            preparedStatement.setString(1, xmlDocument.toString());  

            preparedStatement.executeUpdate();

        } catch (SQLException e) {
            logger.warn(e);
        }

Using either the Element or the Document toString() methods result in an exception ....
java.sql.SQLException: Invalid XML DOCUMENT: Content is not allowed in prolog.

Can someone suggest what I am doing wrong here? 

Cheers,
Jay

_________________________________________________________________
Be the filmmaker you always wanted to be—learn how to burn a DVD with Windows®.
http://clk.atdmt.com/MRT/go/108588797/direct/01/
Mime
View raw message