29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

* params (optional) : Values to be used for where clause in the query.<br />

* query (optional) : Will override the query sting in the xstFile.<br />

*/<br />

//Sets the location of the xst file - the directory path will need to be<br />

changed for you system<br />

String xstFile = "/Documents and Settings/bogers/My<br />

Documents/<strong>IBM</strong>/wasexpress51/workspace/OnlineCatalog/WebContent/featured_item/Fea<br />

turedItem.xst";<br />

if (xstFile == null)<br />

error(response, new Exception("xstFile parameter is not specfied."));<br />

String params = getParameter(req,"params");<br />

String query = getParameter(req,"query"); // if recursive query mode<br />

/*<br />

* Generate XML and XSL streams from the query<br />

*/<br />

try<br />

{<br />

QueryProperties prop = new QueryProperties();<br />

prop.load(xstFile);<br />

if (query != null) // Recursive & ID_AND_IDREF query mode<br />

prop.setStatement(query); // Override the previous query<br />

SQLToXML sql2xml = new SQLToXML(prop);<br />

ByteArrayOutputStream baosXML = new ByteArrayOutputStream();<br />

PrintWriter xmlWriter = new PrintWriter(baosXML);<br />

//ByteArrayOutputStream baosXSL = new ByteArrayOutputStream(); //Not used<br />

in our sample<br />

//PrintWriter xslWriter = new PrintWriter(baosXSL); //Nnot used in our<br />

sample<br />

Connection conn =<br />

getConnection(prop.getLoginId(),prop.getPassword(),response);<br />

if (conn != null)<br />

sql2xml.setConnection(conn); // You are using your own connection<br />

sql2xml.setParameters(params); // null is ok when the query does not<br />

contain where clause<br />

sql2xml.setXMLWriter(xmlWriter); // Generate XML<br />

//sql2xml.setXSLWriter(xslWriter); // Generate default XSL - Not used in<br />

our sample<br />

sql2xml.execute();<br />

Chapter 10. Working with XML 345

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!