1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
3
<!--Converted with LaTeX2HTML 2002-2-1 (1.71)
4
original version by: Nikos Drakos, CBLU, University of Leeds
5
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
6
* with significant contributions from:
7
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
10
<TITLE>Example Walk-Through</TITLE>
11
<META NAME="description" CONTENT="Example Walk-Through">
12
<META NAME="keywords" CONTENT="jsdbc_wp">
13
<META NAME="resource-type" CONTENT="document">
14
<META NAME="distribution" CONTENT="global">
16
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
17
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
19
<LINK REL="STYLESHEET" HREF="jsdbc_wp.css">
25
<H1><A NAME="SECTION00030000000000000000"></A>
26
<A NAME="s1:demo"></A>
33
<DIV ALIGN="CENTER"><A NAME="fig:demo1_login"></A><A NAME="113"></A>
35
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 2:</STRONG>
36
Demo Login Page</CAPTION>
41
WIDTH="500" HEIGHT="455" ALIGN="BOTTOM" BORDER="0"
42
SRC="./demo_login.gif"
43
ALT="Image demo_login">
50
The <SMALL>DBC-JS</SMALL> API consists of three objects:
53
<LI><SPAN CLASS="textbf"><SMALL>RDB</SMALL></SPAN>, corresponding to a database (or connection) handle.
55
<LI><SPAN CLASS="textbf"><SMALL>RDBSTATEMENT</SMALL></SPAN>, corresponding to a statement handle.
57
<LI><SPAN CLASS="textbf"><SMALL>RDBEXCEPTION</SMALL></SPAN>, thrown when <SMALL>DBC-JS</SMALL> detects an error.
62
<TT>demos/runsql.html</TT> is a minimalistic demonstration of the <SMALL>DBC-JS</SMALL> API.
63
The application consists mostly of JavaScript functions that build the web-page
64
and exercise the <SMALL>DBC-JS</SMALL> API. The DOM API is used to create and modify the
68
Using <TT>createLoginPage()</TT>, the demo first creates and displays a
69
login-page (see Figure <A HREF="#fig:demo1_login">2</A>) into which a user enters the data
70
source name, user name and password, and the url to the <SMALL>DBC-JS</SMALL> gateway. The
71
demo then checks (in <TT>submitLogin()</TT>) - by trying to create a
72
corresponding <SPAN CLASS="textbf"><SMALL>RDB</SMALL></SPAN> instance - whether the user is authorized to access the
73
specified data source. If she is, the demo first saves the login-form
74
information, and then uses <TT>createSQLPage()</TT> to replace the login-page
75
with an execute-sql page. If the user cannot be authenticated (an exception is
76
caught), an error message is inserted in the login-page.
80
<DIV ALIGN="CENTER"><A NAME="fig:demo1_results"></A><A NAME="126"></A>
82
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 3:</STRONG>
83
Demo Query Results Page</CAPTION>
88
WIDTH="500" HEIGHT="455" ALIGN="BOTTOM" BORDER="0"
89
SRC="./demo_results.gif"
90
ALT="Image demo_results">
97
The execute-sql page allows the user to enter an <SMALL>SQL</SMALL> statement that will be
98
executed on the database server. Any <SMALL>SQL</SMALL> statement - not only queries - can
99
be executed. This is implemented in <TT>executeSQL()</TT>, where the demo:
102
<LI>creates an <SPAN CLASS="textbf"><SMALL>RDB</SMALL></SPAN> instance,
104
<LI>creates a <SPAN CLASS="textbf"><SMALL>RDBSTATEMENT</SMALL></SPAN> via <TT>RDB.prepare()</TT>,
106
<LI>executes the <SMALL>SQL</SMALL> via <TT>RDBStatement.execute()</TT>.
108
<LI>displays the columns of a query's result-set via
109
<TT>RDBStatement.columnNames()</TT>: the result-set itself (in
110
<TT>createTableHead()</TT> and <TT>createTableBody()</TT>) is displayed using
111
<TT>RDBStatement.fetch()</TT>.
116
As shown in Figure <A HREF="#fig:demo1_results">3</A>, the results of the <SMALL>SQL</SMALL> statement
117
(whether valid or invalid) are displayed to the user who can then execute
118
further statements. With respect to error checking, note how the demo wraps
119
invocations of the <SMALL>DBC-JS</SMALL> API with a <TT>try/catch</TT> of <SPAN CLASS="textbf"><SMALL>RDBEXCEPTION</SMALL></SPAN>: if
120
this exception occurs, its state is passed to <TT>setStatus()</TT> which
121
displays an error message (Figure <A HREF="#fig:demo1_error">4</A>).
125
<DIV ALIGN="CENTER"><A NAME="fig:demo1_error"></A><A NAME="145"></A>
127
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 4:</STRONG>
128
Demo Error Report Page</CAPTION>
133
WIDTH="500" HEIGHT="387" ALIGN="BOTTOM" BORDER="0"
134
SRC="./demo_error.gif"
135
ALT="Image demo_error">