HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"Use XML Inside Existing Applications…"
Vol. 7, Issue 2, p. 36


Listing 1

//  Get list of orders placed since yesterday
ResultSet PurchaseOrder = stmt.executeQuery (
                from ORDERS
                where ORDERDATE > {fn CURDATE()} - 1");

while (PurchaseOrder.next() ) {
        int CustomerId = PurchaseOrder.getInt ("CUSTOMERID");
        int OrderId = PurchaseOrder.getInt ("ORDERID");
        int Quantity = PurchaseOrder.getInt ("QUANTITY");
        String Item = PurchaseOrder.getString ("ITEM");
        String Item = PurchaseOrder.getString ("EXTRADETAIL");

        // internal business rules dictate how purchase order is processed


Listing 2

//  Iterate through customer sites to see if there are orders

// we'll use two JDBC connections ... one for our internal Oracle tables and one to the
//     XML streaming information from the web

// Oracle ...
Connection  Oraclecon = DriverManager.getConnection (OracleDriverURL, uid, pwd);
Statement stmt = Oraclecon.createStatement()

// XML ...
Connection XMLCon = DriverManager.getConnection (XMLDriverURL, Xuid, Xpwd);
Statement XMLstmt = XMLCon.createStatement();

//  Internally, we'll have an Oracle table called CUSTOMERS that tracks all our customers
//    as well as from which URL we can obtain their order information ... provided they can
//    post e-orders

//  For Customers that can process orders online ... get the URL where we collect order info.
//    The URL will have a form similar to HTTP://www.acme.com/MyCoorders.asp
ResultSet Customer = stmt.executeQuery (
                from CUSTOMERS
                where ONLINEORDERS = 'T' ");

while (Customer.next() ) {
        int CustomerId = Customer.getInt ("CUSTOMERID");
        String CustomerURL = Customer.getString ("CUSTOMERURL");

// see if the customer placed any orders by reading a dynamically generated XML document
//   that contains their order information from their website and, if so,
//   insert the order into our ORDERS table
        ResultSet  NewOrder = XMLstmt.executeQuery (
                "select QUANTITY, ITEM, DETAIL from " + CustomerURL +
                        "where ORDERDATE > {fn CURDATE()} - 1");

        while (NewOrder.next() ) {

                // customer placed order ... gather data and insert the order into our Oracle ORDERS table



Listing 3

//   Build a copy of the catalog as an XML Document that can be exposed to customers

// Query for the products currently available and include the FOR XML AUTO clause
//  which will instruct SQL Server to return the result as an XML Document
ResultSet OurCatalog  = stmt.executeQuery (
              where PRODUCTFORSALE = 1 FOR XML AUTO");

while (OurCatalog..next() ) {
        // 3 columns selected but only 1 returned ... the XML Document that corresponds
        //   to the result set produced from the query
        String XMLCatalog = OurCatalog.getString (1);

        // the XML Document now sits in our XMLCatalog data structure which can
        //  be written to a file


Listing 4

//   Build a copy of the catalog as an XML Document that can be exposed to customers

// Query for the products currently available, which will result in an XML-formatted result
StringBuffer OurCatalog = new StringBuffer();
OurCatalog.append ("select xml_element ('product-id',p.PRODUCTID),");
OurCatalog.append (" xml_element('product-description',p.DESCRIPTION),");
OurCatalog.append (" xml_element('product-price',p.PRICE) ");
OurCatalog.append (" from PRODUCTS p where p.PRODUCTFORSALE = 1");

// Construct object to execute
JXTRQuery ProductCatalog = new JXTRQuery (conn, new String (OurCatalog));

// Execute, generate XML, and write to file
ProductCatalog.executeWriter (systemOutWriter,


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.