Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
Using XSQL Servlet, 7 of 24
XSQL Pages refer to database connections by using a "nickname" for the connection defined in the XSQL configuration file. Connection names are defined in the <connectiondefs>
section of XSQLConfig.xml
file like this:
: <connectiondefs> <connection name="demo"> <username>scott</username> <password>tiger</password> <dburl>jdbc:oracle:thin:@localhost:1521:testDB</dburl> <driver>oracle.jdbc.driver.OracleDriver</driver> </connection> <connection name="prod"> <username>prodapp</username> <password>sumpti0us</password> <dburl>jdbc:oracle:thin:@localhost:1521:prodDB</dburl> <driver>oracle.jdbc.driver.OracleDriver</driver> </connection> </connectiondefs> :
Any number of <connection> elements can be placed in this file to define the connections you need. An individual XSQL Page refers to the connection it wants to use by putting a connection="xxx" attribute on the top-level element in the page (also called the "document element").
For a page with a single query this looks like:
<?xml version="1.0"?> <xsql:query connection="demo" xmlns:xsql="urn:oracle-xsql"> SELECT * FROM DUAL </xsql:query>
For a page with more than one query, it looks like the following:
<?xml version="1.0"?> <page connection="demo" xmlns:xsql="urn:oracle-xsql"> <xsql:query>SELECT 'X' as X FROM DUAL</xsql:query> <xsql:query>SELECT 'Y' as Y FROM DUAL</xsql:query> </page>
You can use these techniques to publish an XML-based product catalog.
Table 19-1 lists three useful and common XSQL Servlet tags. For a full list of tags see Oracle8i XML Reference.
Save the file and request it through your browser to get immediate results.
Here is another simple example of an XSQL Page. This could be in response to a URL request such as:
http://yourcompany.com/AvailableFlightsToday.xsql?City=NYC
An example XSQL Page:
<?xml version="1.0"?> <xsql:query connection="demo" xmlns:xsql="urn:oracle-xsql"> SELECT Carrier, FlightNumber, Origin, TO_CHAR(ExpectedTime,'HH24:MI') Due FROM FlightSchedule WHERE TRUNC(ArrivalTime) = TRUNC(SYSDATE) AND Destination = '{@City}' ORDER BY ExpectedTime </xsql:query>
To return the information in HTML or other XML format that complies with a DTD, add a <?xml-stylesheet....?> tag such as:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="FlightList.xsl"?> <xsql:query connection="demo" xmlns:xsql="urn:oracle-xsql"> SELECT Carrier, FlightNumber, Origin, TO_CHAR(ExpectedTime,'HH24:MI') Due FROM FlightSchedule WHERE TRUNC(ArrivalTime) = TRUNC(SYSDATE) AND Destination = '{@City}' ORDER BY ExpectedTime </xsql:query>
Table 19-2 lists several supplied built-in XSQL Action Elements
.
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|