queryProperties.setFormat("GENERATE_AS_ELEMENTS"); queryProperties.setRecurse(false);

}

Executing the SQLToXML class

We created the doQuery method to execute the query and get an XML Document as a result (Example 11-8). SQLToXML returns XML data as a stream, and it only accepts an instance of PrintWriter. To get it as a string data, you need to create an instance of StringWriter, then create an instance of PrintWriter from the StringWriter.

Tip: A future release of Application Developer contains a method to get a document. We tested this method and it works. When it is available, you can get a document directory from SQLToXML.

Example 11-8 CustomerXSLServlet doQuery method

//For Application Developer 4.0.3

private StringWriter doQuery(HttpServletRequest request){ StringWriter xmldata = new StringWriter(); PrintWriter xmlwr = new PrintWriter(xmldata);

try{

sql2xml.execute(new java.lang.String( request.getParameter("memberhsip")),xmlwr,null,null,null);

}catch(Exception exception){ System.out.println(exception);

}

return xmlData;

}

//For Application Developer 5.0

private org.w3c.dom.Document doQuery(HttpServletRequest request){ StringWriter xmldata = new StringWriter();

PrintWriter xmlwr = new PrintWriter(xmldata);

try{

sql2xml.setParameters(new java.lang.String( request.getParameter("memberhsip")));

sql2xml.execute();

}catch(Exception exception){ System.out.println(exception);

}

return sql2xml.getDocument();

}

272 The XML Files: Development of XML/XSL Applications Using WebSphere Studio

Page 288
Image 288
IBM Version 5 manual Executing the SQLToXML class, Example 11-8 CustomerXSLServlet doQuery method