Sunday, August 08, 2010

XSQL page Framework using JDeveloper

Before using XSQL i would recommend to get an idea of xquery.

Please read about xquery from w3schools.com to get an initial idea about it.

If you have basic idea on x query then we are good to go.

X-Sql page is basically a xml file with .xsql extension.It contains XML and XSQL and has a root element with following namespace

xmlns:xsql="urn:oracle-xsql"

We will just directly jump in to exercise and try to understand how does it work.

Open up jdeveloper.

Create a new Application and then a new empty project file.

Now right click on the project that you have created and choose new.

Now Select XML in General tab and then XSQL file in the Items tab as shown below.





Give it some logical name and say ok.



So if you will now see in to you jdeveloper you will find that jdeveloper has created three things for you

1>XSQLConfig.xml file
2>web.xml
3>sample.xsql


We will check the XSQLConfig.xml file.If you will browse in this file you will find somewhere following tags

<connectiondefs>

<connection name="demo">
<username>scott</username>
<password>tiger</password>
<dburl>jdbc:oracle:thin:@localhost:1521:ORCL</dburl>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<autocommit>true</autocommit>
</connection>
<connection name="xmlbook">
<username>xmlbook</username>
<password>xmlbook</password>
<dburl>jdbc:oracle:thin:@localhost:1521:ORCL</dburl>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<autocommit>true</autocommit>
</connection>
<connection name="lite">
<username>system</username>
<password>manager</password>
<dburl>jdbc:Polite:POlite</dburl>
<driver>oracle.lite.poljdbc.POLJDBCDriver</driver>
</connection>

</connectiondefs>


This is the default connection definition created by jdeveloper.




I have created my own user arpit and password arpit so i will be using those details in my configuration.




Now i will just double click on the query button on the xsql component pallete.It will come up with something like this.



Say next and create a new connection.

Give some logical name to it and say next






Provide details




and verify the connection to come to this page



Now in the next page provide the sql query you wanna perforn and say finish




keep in mind that you need not specify the semicolon

you will find the following code

<?xml version = '1.0' encoding = 'windows-1252'?>
<!--
| Uncomment the following processing instruction and replace
| the stylesheet name to transform output of your XSQL Page using XSLT
<?xml-stylesheet type="text/xsl" href="YourStylesheet.xsl" ?>
-->
<page xmlns:xsql="urn:oracle-xsql" connection="jdbc/arpitDS">
<xsql:query max-rows="-1" null-indicator="no" tag-case="lower">
select * from customer
</xsql:query>
</page>


Now in the jdeveloper select the .xsql file you have created and say run ,it will start the embedded oc4j server and open browser and fetch you the result in the web page.




it will open a browser and you see the following output here

<?xml version="1.0" encoding="windows-1252" ?>
- <!--
| Uncomment the following processing instruction and replace
| the stylesheet name to transform output of your XSQL Page using XSLT
<?xml-stylesheet type="text/xsl" href="YourStylesheet.xsl" ?>


-->
- <page>
- <rowset>
- <row num="1">
<name>ankit</name>
<empid>22222</empid>
</row>
</rowset>
</page>

No comments: