Java Reference
In-Depth Information
<PHONE>201-555-1216</PHONE>
</CUSTOMER>
<CUSTOMER CUSTOMER_NUMBER="105">
<FIRST_NAME>Fred</FIRST_NAME>
<MI>Q</MI>
<LAST_NAME>Bloggs</LAST_NAME>
<STREET>22 Walnut</STREET>
<CITY>New York</CITY>
<STATE>NY</STATE>
<ZIP>10006</ZIP>
<PHONE>201-555-1217</PHONE>
</CUSTOMER>
</CustomerDB>
Note that although the
SQL CREATE
command specifies type
VARCHAR (30)
for most of the fields, this
type specification defaults to String. The reason for this is that all data is stored as a String, and the only
significance attached to data type is to check for the custom type
ATTRIBUTE
, which is used to denote
that the field should be added to the row element as an attribute.
Note also that the XML document must be saved after each update. The XML database actually exists
as a DOM document in memory, so it must be serialized after changes are made.
Tests are carried out using a variety of different queries. These queries include the following:
SELECT * FROM CUSTOMER
SELECT * FROM CUSTOMER WHERE FIRST_NAME LIKE 'M%'
SELECT * FROM CUSTOMER WHERE FIRST_NAME NOT LIKE 'M%'
SELECT * FROM CUSTOMER WHERE FIRST_NAME NOT = 'Michael'
SELECT * FROM CUSTOMER WHERE FIRST_NAME <> 'Michael'
SELECT * FROM CUSTOMER WHERE FIRST_NAME LIKE 'M%' OR FIRST_NAME LIKE 'F%'
SELECT * FROM CUSTOMER WHERE (FIRST_NAME LIKE 'M%' OR FIRST_NAME LIKE 'V%')
SELECT * FROM CUSTOMER WHERE ( FIRST_NAME LIKE 'M%' OR CUSTOMER_NUMBER =
'102' )
In addition to supporting the
ResultSet.getString()
method used to set the
String
variables in
Listing 19-12
, the
XMLResultSet
can also be retrieved as an XML document.
Listing 19-14
shows the
XMLResultSet
generated by running this query:
SELECT * FROM CUSTOMER WHERE
( FIRST_NAME LIKE 'M%' OR CUSTOMER_NUMBER = '102' ) AND LAST_NAME =
'Corleone'
Listing 19-14: XMLResultSet
<?xml version="1.0"?>
<RESULTSET>
<CUSTOMER CUSTOMER_NUMBER="100">
<FIRST_NAME>Michael</FIRST_NAME>
<MI>A</MI>
<LAST_NAME>Corleone</LAST_NAME>