Solved

Oracle to write XML?

Posted on 2002-05-01
7
1,278 Views
Last Modified: 2007-11-27
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
Comment
Question by:kpu8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
sora earned 50 total points
ID: 6985105
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
 

Expert Comment

by:myexpert2002
ID: 6985287


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
 
LVL 5

Expert Comment

by:sora
ID: 6985309

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Expert Comment

by:myexpert2002
ID: 6985332


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
 
LVL 5

Expert Comment

by:sora
ID: 6985344
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
 
LVL 1

Author Comment

by:kpu8
ID: 6989055
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
 
LVL 1

Author Comment

by:kpu8
ID: 6994688
Thanks - this got me going in the right direction
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question