jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes XMLType Column Oracle - InsertIntoDB - Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "XMLType Column Oracle - InsertIntoDB - Exception" Watch "XMLType Column Oracle - InsertIntoDB - Exception" New topic

XMLType Column Oracle - InsertIntoDB - Exception

Ravishankar Dhamodharan

Joined: Feb 20, 2012
Posts: 1
I am trying to insert a well structured XML into an XMLType Column. Please refer below for my code sinppet, table structure and Exception.
Could you please help me to over come this exception.

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import oracle.jdbc.OracleCallableStatement;
import oracle.xdb.XMLType;
public class InsertEDXMLtoDB {

// Using String - byteBuffer - InputStream

public static void main (String a[]) throws FileNotFoundException

String Cit="CIT_123";
String xmlText="<PO><PONO>200</PONO><PNAME>PO_2</PNAME></PO>";

try {
Class.forName("oracle.jdbc.OracleDriver") ;
Connection conn = DriverManager.getConnection("jdbcracle:thin:@IP:1521rcl","scott", "tiger");
String statementText="insert into EdXML (CIT,XML_DOCUMENT) values(?,?)";

byte[] byteBuffer = xmlText.getBytes();
InputStream is = new ByteArrayInputStream(byteBuffer);
XMLType xml;
xml = XMLType.createXML(conn,is);

OracleCallableStatement statement = null;
statement = (OracleCallableStatement) conn.prepareCall(statementText);
statement.setString(1, LNCit);
boolean result = statement.execute();

} catch (SQLException e) {
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
} finally {

Table Structure:

SQL> desc EdXML;
Name Null? Type
----------------------------------------- -------- -----------------


Exception in thread "main" java.lang.NoSuchFieldError: conversion
at oracle.xdb.XMLType.<init>(XMLType.java:529)
at oracle.xdb.XMLType.createXML(XMLType.java:443)
at InsertEDXMLtoDB.main(InsertEDXMLtoDB.java:41)

I tried all the code snippet availble on Net and got the same above exception. Wherein if I have the XMLTYpe Column as CLOB the above works good, but my requirement
goes with the XMLType Column.

It could be great help for me if someone suggest how to do the same with the Spring JDBC Template. [Inserting XML to XMLType Column Type using Spring JDBC Template]

Kindly help me out in this matter.
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

I didn't ever use XMLType in Oracle, but it seems to be covered quite thoroughly in the documentation. It seems that you can bind your XML data as a CLOB and use a function to convert it into XMLTYPE in your insert statement (see example 11-15 on that page).

If you're using a JDBC driver older than 11g, you'll probably want to look up the matching documentation version.
I agree. Here's the link: http://aspose.com/file-tools
subject: XMLType Column Oracle - InsertIntoDB - Exception
It's not a secret anymore!