Translating the XML ResultSet document in the client

The main( ) method of ResultSetXml is executed in a client environment. It copies the file OrderResultSet.xml, constructs a ResultSetXml object containing the contents of that file, and invokes the toSqlScript( ) method of that object to generate a SQL script that re-creates the data of the result set. The method stores the SQL script in the file order-resultset-copy.sql.

import java.io.*;
import jcs.util.*;
public class ResultSet2Sql{
    public static void main (String[] args) {
       try{
          String xml = FileUtil.file2String("OrderResultSet.xml");
			xml.resultset.ResultSetXml rsx  
 			= new xml.resultset.ResultSetXml(xml);
          String sqlScript 
 			= rsx.toSqlScript("orderresultset_copy", "col_","no");
          FileUtil.string2File("order-resultset-copy.sql",sqlScript);
			ExecSql.statement(sqlScript,“antibes:4000?user=sa”);
       } catch (Exception e) {
          System.out.println("Exception:");
          e.printStackTrace();
       }
    }
 }

This is the SQL script generated by ResultSet2Sql.

set quoted_identifier on 
 create table orderresultset_copy ( 
    Date datetime not null , 
    CustomerId varchar (5) not null , 
    CustomerName varchar (50) not null , 
    ItemId varchar (5) not null , 
    ItemName varchar (20) not null , 
    Quantity integer not null , 
    unit smallint not null 
 )
insert into orderresultset_copy values (
    '1999-07-04 00:00:00.0',   '123', 
 	'Acme Alpha',    '987', 'Widget', 5,  1 )
 insert into orderresultset_copy values (
    '1999-07-04 00:00:00.0',  '123',  
 	'Acme Alpha',  '654',  
 	'Medium connecter',  3,  12 )
 insert into orderresultset_copy values (
 	'1999-07-04 00:00:00.0',  '123',  
 	'Acme Alpha',  '579',  'Type 3 clasp',  1,  1 )

The SQL script includes the set quoted_identifier on command for those cases where the generated SQL uses quoted identifiers.