1

I have a Query, which I execute in SQL server 2005/2008, gives me output in XML format.

Here is the sample query to generate xml output :

SELECT 
    (SELECT 'White' AS Color1,
            'Blue' AS Color2,
            'Black' AS Color3,
            'Light' AS 'Color4/@Special',
            'Green' AS Color4,
            'Red' AS Color5 
    FOR XML PATH('Colors'),TYPE),
    (SELECT 'Apple' AS Fruits1,
            'Pineapple' AS Fruits2,
            'Grapes' AS Fruits3,
            'Melon' AS Fruits4 
    FOR XML PATH('Fruits'),TYPE) 
FOR XML PATH(''),ROOT('SampleXML')

What I need is, to read the output in Java to convert it to a java.io.File format, so I can parse and populate objects.

I tried : SQLXML sqlxml = resultSet.getSQLXML(column);, which is given in here

But it is throwing an exception : Exception in thread "main" java.lang.AbstractMethodError: com.inet.pool.g.getSQLXML(I)Ljava/sql/SQLXML;

Please suggest me a way to read the file.

Plz Note : I am able to read the o/p as String using resultSet.getString(column), but not able to parse it.

1 Answer 1

2

The SQLXML interface provides methods for accessing the XML value as a String, a Reader or Writer, or as a Stream.put the sqlxml into binary stream and parse the xml

SQLXML sqlxml = resultSet.getSQLXML(column);
InputStream binaryStream = sqlxml.getBinaryStream();
Sign up to request clarification or add additional context in comments.

2 Comments

it is throwing an exception : Exception in thread "main" java.lang.AbstractMethodError: com.inet.pool.g.getSQLXML(I)Ljava/sql/SQLXML;
are you using which version of java?SQLXML is support for java 1.6 version.if your using java 1.6 The dbcp library in server must have been compiled against a previous JDK version which doesn't support XML related methods in the SQL classes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.