This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "XMLType Column Oracle - InsertIntoDB - Exception" Watch "XMLType Column Oracle - InsertIntoDB - Exception" New topic
Author

XMLType Column Oracle - InsertIntoDB - Exception

Ravishankar Dhamodharan
Greenhorn

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);
statement.setObject(1,xml);
boolean result = statement.execute();


} catch (SQLException e) {
System.out.println(e);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
}
}
}

Table Structure:

SQL> desc EdXML;
Name Null? Type
----------------------------------------- -------- -----------------
CIT VARCHAR2(64)
XML_DOCUMENT XMLTYPE

SQL>

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
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

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.
 
Don't get me started about those stupid light bulbs.
 
subject: XMLType Column Oracle - InsertIntoDB - Exception
 
Similar Threads
can´t read the Oracle´s XMLTYPE generated in a query in my JSP page
Getting a SQL Exception ?
Bind Variable?
need java logic
More problems with file uploads