Solved

Oracle to write XML?

Posted on 2002-05-01
7
1,257 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

803 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