import java.sql.*;
import java.math.*;
import oracle.xml.sql.query.*;
import oracle.jdbc.*;
import oracle.jdbc.driver.*;


public class OraXmlTest
{
  public static void main(String args[]) throws SQLException
  {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    //initiate a JDBC connection
    Connection conn =
      DriverManager.getConnection("jdbc:oracle:thin:@[host]:[port]:[sid]", "[userid]", "[password]");

    // initialize the OracleXMLQuery
    OracleXMLQuery qry = new OracleXMLQuery(conn,"select EMPNO, ENAME from emp" );

    // structure the generated XML document
    qry.setMaxRows(2);  // set the maximum number of rows to be returned
    qry.setRowsetTag("ROOTDOC"); // set the root document tag
    qry.setRowTag("DBROW"); // sets the row separator tag
    //qry.setStyleSheet("emp.xsl"); // sets the stylesheet

    // get the XML document in string format
    String xmlString = qry.getXMLString();

    // print out the XML document
    System.out.println(" OUTPUT IS:\n"+xmlString);
  }
}
1