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:
Execute a SQL query for the Order data
Generate an XML Order document with the data
Return the OrderXml object that contains the Order document
You can invoke the OrderXml constructor on the client or the IQ server.
If you invoke the OrderXml constructor on the client, the JDBC operations that it performs use jConnect to connect to the IQ server and perform the SQL query. The constructor then reads the result set of that query and generates the Order document on the client.
If you invoke the OrderXml constructor on the IQ server, the JDBC operations that it performs use the native JDBC driver to connect to the current IQ server and perform the SQL query. The constructor then reads the result set and generates the Order document on the IQ server.
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(); } } }
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', '')