File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how to use data of type XMLTYPE in database in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to use data of type XMLTYPE in database in java" Watch "how to use data of type XMLTYPE in database in java" New topic
Author

how to use data of type XMLTYPE in database in java

Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
I have a table with different columns and one of the columns is of the type XMLTYPE. i want to retrieve data from stored procedure and use it in Java, also update it when required.

Can anyone come up suggestions, as i havent used XMLTYPE so far ? sample code will be beneficial
[ October 28, 2004: Message edited by: mvk ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30501
    
150

"mvk",
We're pleased to have you here with us in the JDBC forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
Forum Bartender


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Thanks for the information. I changed my display name.

I would appreciate a solution now : x()
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Which Database are you using? I'd expect you'd have to consult your DB/Driver documentation for an answer. After quick glace at my Oracle docs, it seems you use the Oracle specific Class oracle.xdb.XMLType with this data type. Probably different on other platforms, if they support this type.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Hi Paul ,

We are using Oracle Database. Per our architecture, Stored procedure will return this COLUMN of type XMLTYPE, along with other values. I would like to retrieve it along with other values. I think i might have to parse the values from the XMLTYPE data.

Again, any sample code will be helpful.

Thanks for your response
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Check out the Oracle documentation. There is example code for using XMLType via JDBC.
nilesh Katakkar
Ranch Hand

Joined: Oct 27, 2004
Posts: 35
If you want to deal with XMLTYPE in JDBC code then you will have to use Oracle driver's extension -

XMLType xml = XMLType.createXML(resultSet.getOPAQUE("xmlColumn"));

There are multiple ways to deal with XMLType in your JDBC code. One is to use Oracle Specific extension as above, You can also use JAVA DOM API with Oracle extension. You can find enough examples in online documentation.

Other simple way to avoid Oracle specific extensions would be to make your stored procedure return CLOB or String for XMLType.

The Select statement in SP would look like

SELECT e.xmlColumn.getStringVal() from table e -- for String
SELECT e.xmlColumn.getClobVal() from table e -- for Clob


nilesh<br />neilindallas@hotmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use data of type XMLTYPE in database in java