Composing Order documents from SQL data

In this example, Java methods generate an XML Order document from the SQL data in the tables created in “Creating and populating SQL tables for Order data”.

A constructor method of the OrderXml class maps the data. A call of that constructor is:

new jcs.xml.orders.OrderXml("990704", "123",
 	“external”, "antibes:4000?user=DBA&password=SQL");

This constructor method uses internal JDBC operations to:

You can invoke the OrderXml constructor on the client or the IQ server.


Generating an Order on the client

Designed to be implemented on the client, main( ) invokes the constructor of the OrderXml class to generate an XML Order from the SQL data. That constructor executes a select for the given date and customer id, and assembles an XML Order document from the result.

import java.io.*;
import jcs.util.*;
public class Sql2OrderClient {
 	public static void main (String args[]) {
 		try{
 			jcs.xml.orders.Order orders = 
 				new jcs.xml.orders.OrderXml("990704", "123",
 				“external”, "antibes:4000?user=DBA&password=SQL");
 			FileUtil.string2File("Order-sql2Order.xml",
 				orders.getXmlText());
 		} catch (Exception e) {
 		System.out.println("Exception:");
 		e.printStackTrace();
 		}
 	}
 }

Generating an Order on the server

Designed for the server environment, the following SQL script invokes the constructor of the OrderXml class to generate an XML Order from the SQL data:

create variable orders jcs.xml.orders.OrderXml
set orders = 
 	new jcs.xml.orders.OrderXml('990704', '123',
 	'external', '')