• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1325
  • Last Modified:

Oracle to write XML?

I have the following Oracle 8i sample code which I'm trying to use to write XML from the db which gives me the error when I compile it with the JDK 1.2
Class oracle.xml.sql.query.OracleXMLQuery not found in import

I found a post in a message board which says to import xsu11.jar and xsu12.jar if this is so - I do I do this -
what can I do to fix this error

import oracle.jdbc.driver.*;
import oracle.xml.sql.query.OracleXMLQuery;
import java.lang.*;
import java.sql.*;

// class to test the String generation!
class testXMLSQL {

   public static void main(String[] argv)
   {

     try{
      // create the connection
      Connection conn  = getConnection("jdbc:oracle:oci8:@myserver:myport:myprefix",myname,mypassword);

      // Create the query class.
      OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from mytable");

      // Get the XML string
      String str = qry.getXMLString();

      // Print the XML output
      System.out.println(" The XML output is:\n"+str);
      // Always close the query to get rid of any resources..
     qry.close();
     }catch(SQLException e){
      System.out.println(e.toString());
     }
   }

   // Get the connection given the user name and password..!
   private static Connection getConnection(String username, String password)
     throws SQLException
   {
      // register the JDBC driver..
       DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());


      // Create the connection using the OCI8 driver
       Connection conn =
       DriverManager.getConnection("jdbc:oracle:oci8:@myserver:myport:myprefix",myname,mypassword);


      return conn;
   }
}  
0
kpu8
Asked:
kpu8
  • 3
  • 2
  • 2
1 Solution
 
soraCommented:
Are you trying to run the java code within the database using Oracle JServer or using your own o/s JVM? If they are attempted to be run inside the database, they must be loaded first. If not, then note the following:

XSU is written in Java, and XSU classes are stored in one of the following files depending upon the environment:

    - XSU12.jar for JDK 1.2 and 8.1.6 database
    - XSU111.jar for jdk 1.1.x and 8.1.5 database

since you are using jdk 1.2, use only the XSU12.jar file.

XSU uses Oracle's XML Parser to process the XML documents. The Java classes for XML parser are stored in XMLPARSERV2.jar file.

XSU also needs the appropriate JDBC driver in order to access the database.

The CLASSPATH environment variable should point to the required files:

   -  XSU jar file
   -  XML Parser jar file
   - JDBC Driver zip file.

e/g

import <full path>/xsu12.jar
import <full path>/XMLPARSERV2.jar

e/g

import /u01/dev/java/oracle/classes/xsu12.jar
or
import c:\dev\java\classes\oracle\xsu12.jar


To run the XSU inside the database, Java classes for the XSU and XML Parser have to be loaded into
the database.

See whether the class OracleXMLQuery is located in those 2 jar files you mentioned - xsu11.jar and xsu12.jar by using the following command:

   $  jar tf xsu12.jar      (java is case sensitive!)

See this article on technet:
http://technet.oracle.com/docs/tech/xml/oracle_xsu/doc_library/adx04xsu.html

(you need an account but it is free)

Some more information on Metalink: Doc Id:120841.1. Have copy-pasted from Metalink,( in case you do not have access let me know.)


For more on working with Jar files, here's some info right from the horses mouth:

http://java.sun.com/docs/books/tutorial/jar/basics/index.html

Good Luck!


sora
0
 
myexpert2002Commented:


hi kpu8,

   just set the classpath in the environment variables.and restart the system. and run the program.

U will find these jars files in Oraclehome folder,search in it.

Needed jar files are
    XSU12.jar
    XSU111.jar
    XMLPARSERV2.jar


BYE,
Pramod
0
 
soraCommented:

kpu8

From my previous post:

The CLASSPATH environment variable should point to the required files:

  -  XSU jar file
  -  XML Parser jar file
  - JDBC Driver zip file.

then import the class as follows:

import oracle.xml.sql.query.OracleXMLQuery



sora
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
myexpert2002Commented:


hi kpu8,

   just set the classpath in the environment variables.and restart the system. and run the program.

U will find these jars files in Oraclehome folder,search in it.

Needed jar files are
    XSU12.jar
    XSU111.jar
    XMLPARSERV2.jar


BYE,
Pramod
0
 
soraCommented:
Pramod -

Friendly suggestion - if you could read through previous posts, and avoid posting duplicate information, it would be ever so good.

Secondly, since kpu8 said he is using jdk1.2, you DO NOT need xsu111.jar

sora
0
 
kpu8Author Commented:
Ok well running the command:

jar tf xsu12.jar

I get the following message (but it appears I may an older JDK 1.2 so once I download the latest version maybe I'll be good following sora's advice - I'll keep you posted as I may run out of time today)

java.io.FileNotFoundException: xsu12.jar
        at java.io.FileInputStream.<init>(FileInputStream.java:69)
        at sun.tools.jar.Main.run(Main.java:139)
        at sun.tools.jar.Main.main(Main.java:721)
0
 
kpu8Author Commented:
Thanks - this got me going in the right direction
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now