Unit Iii WT
Unit Iii WT
Database Connectivity – JDBC Drivers – SQL Statements - XML – Structure in Data – Default
Namespaces – DTD – XSD– Parsing XML.
Exercise: Programs using XML – Schema – XSLT/XSL.
------------------------------------------------------------------------------------------------------------------
Database Connectivity
Database Connectivity refers to the mechanisms that enable application software to
communicate with database management systems (DBMS). Establishing a connection is
essential for performing operations such as creating, reading, updating, and deleting data within a
database.. In other words, a Web database application should comprise the following four layers
(i.e. components):
• Browser layer
• Application logic layer
• Database connection layer
• Database layer
Browser layer
The browser is the client of a Web database application, and it has two major functions. First, it
handles the layout and display of HTML documents. Second, it executes the client-side
extension functionality such as Java, JavaScript, and ActiveX (a method to extend a browser’s
capabilities).
Application logic layer
The application logic layer is the part of a Web database application with which a developer will
spend the most time. It is responsible for:
• Collecting data for a query (e.g. a SQL statement).
• Preparing and sending the query to the database via the database connection layer.
• Retrieving the results from the connection layer.
• Formatting the data for display.
Database connection layer
This is the component which actually links a database to the Web server. The database
connection layer provides a link between the application logic layer and the DBMS.
Database layer
This is the place where the underlying database resides within the Web database application.
JDBC Drivers
JDBC Driver is a software component that enables java application to interact with the database.
There are 4 types of JDBC drivers:
1. JDBC-ODBC bridge driver
2. Native-API driver (partially java driver)
3. Network Protocol driver (fully java driver)
4. Thin driver (fully java driver)
2) Native-API driver
The Native API driver uses the client-side libraries of the database. The driver converts
JDBC method calls into native calls of the database API. It is not written entirely in java.
Advantage:
o performance upgraded than JDBC-ODBC bridge driver.
Disadvantage:
o The Native driver needs to be installed on the each client machine.
o The Vendor client library needs to be installed on client machine.
Advantage:
o No client side library is required because of application server that can perform many
tasks like auditing, load balancing, logging etc.
Disadvantages:
o Network support is required on client machine.
o Requires database-specific coding to be done in the middle tier.
o Maintenance of Network Protocol driver becomes costly because it requires database-
specific coding to be done in the middle tier.
4) Thin driver
The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is
why it is known as thin driver. It is fully written in Java language
Advantage:
o Better performance than all other drivers.
o No software is required at client side or server side.
Disadvantage:
o Drivers depend on the Database.
SQL Statements
o SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
o SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.
XML
Structure in Data
XML data structures consist of elements, nested child elements, and attributes
that Analytics identifies when it analyzes an XML file. They are displayed in the XML Data
Structures treeview, which is a hierarchical representation of the XML file. Each XML data
structure is represented by a table icon, and the name of the XML element and nested elements
or attributes that it contains.
Prior to selecting one or more XML data structures you should review the XML file and
determine a suitable Analytics table structure for your audit objectives. With that table structure
in mind, select only XML data structures with columns that match columns in the intended table
structure. You can use the subsequent pages in the wizard to fine-tune the individual elements to
include, and modify column properties.
If you need to analyze an XML file with a complex structure, you may need to import the
XML file more than once. You can select different data structures for each Analytics table you
create, and then join or relate the tables in Analytics.
Default Namespaces
An XML namespace is declared using the reserved XML attribute. This attribute name must be
started with "xmlns".
Let's see the XML namespace syntax:
<element xmlns:name = "URL">
Here, namespace starts with keyword "xmlns". The word name is a namespace prefix.
The URL is a namespace identifier.
Let's see the example:
<root>
<h:table xmlns:h="http://www.abc.com/TR/html4/">
<h:tr>
<h:td>Aries</h:td>
<h:td>Bingo</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http://www.xyz.com/furniture">
<f:name>Computer table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
In the above example, the <table> element defines a namespace and when a namespace is
defined for an element, the child elements with the same prefixes are associated with the same
namespace.
<root xmlns:h="http://www.abc.com/TR/html4/"
xmlns:f="http://www.xyz.com/furniture">
<h:table>
<h:tr>
<h:td>Aries</h:td>
<h:td>Bingo</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>Computer table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
DTD
DTD stands for Document Type Definition.
A DTD defines the structure and the legal elements and attributes of an XML document.
The purpose of a DTD is to define the structure and the legal elements and attributes of an XML
document.
A "Valid" XML document is "Well Formed", as well as it conforms to the rules of a DTD:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The DOCTYPE declaration above contains a reference to a DTD file.
Example
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ENTITY nbsp " ">
<!ENTITY writer "Writer: Donald Duck.">
<!ENTITY copyright "Copyright: W3Schools.">
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<footer>&writer; ©right;</footer>
</note>
XSD
An XML Schema describes the structure of an XML document.
The XML Schema language is also referred to as XML Schema Definition (XSD).
The purpose of an XML Schema is to define the legal building blocks of an XML document:
the elements and attributes that can appear in a document
the number of (and order of) child elements
data types for elements and attributes
default and fixed values for elements and attributes
In the XML world, hundreds of standardized XML formats are in daily use.
Many of these XML standards are defined by XML Schemas.
XML Schema is an XML-based (and more powerful) alternative to DTD.
XML Schemas Support Data Types
One of the greatest strength of XML Schemas is the support for data types.
It is easier to describe allowable document content
It is easier to validate the correctness of data
It is easier to define data facets (restrictions on data)
It is easier to define data patterns (data formats)
It is easier to convert data between different data types
XML Schemas use XML Syntax
Another great strength about XML Schemas is that they are written in XML.
You don't have to learn a new language
You can use your XML editor to edit your Schema files
You can use your XML parser to parse your Schema files
You can manipulate your Schema with the XML DOM
You can transform your Schema with XSLT
XML Schemas are extensible, because they are written in XML.
With an extensible Schema definition you can:
Reuse your Schema in other Schemas
Create your own data types derived from the standard types
Reference multiple schemas in the same document
XSD Example
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Parsing XML.
XML parser is a software library or a package that provides interface for client
applications to work with XML documents. It checks for proper format of the XML document
and may also validate the XML documents. Modern day browsers have built-in XML parsers.
Following diagram shows how XML parser interacts with XML document −
Types of XML Parsers
These are the two main types of XML Parsers:
1. DOM
2. SAX
Advantages
1) It supports both read and write operations and the API is very simple to use.
2) It is preferred when random access to widely separated parts of a document is required.
Disadvantages
1) It is memory inefficient. (consumes more memory because the whole XML document needs
to loaded into memory).
2) It is comparatively slower than other parsers.
Advantages
1) It is simple and memory efficient.
2) It is very fast and works for huge documents.
Disadvantages
1) It is event-based so its API is less intuitive.
2) Clients never know the full information because the data is broken into pieces.