Java Reference
In-Depth Information
cNum = rs.getString("CUSTOMER_NUMBER");
fName = rs.getString("FIRST_NAME");
lName = rs.getString("LAST_NAME");
street = rs.getString("STREET");
city = rs.getString("CITY");
state = rs.getString("STATE");
zip = rs.getString("ZIP");
phone = rs.getString("PHONE");
}catch (Exception e){
System.out.println(e);
}
}
public static void serializeDocumentAsFile(Document xmlDoc,String
UrlString){
String fileName = "XMLOut.xml";
try {
URL url = new URL(UrlString);
if(url.getProtocol().equals("file")){
fileName = url.getFile().substring(1);
}
OutputFormat fmt = new OutputFormat("xml",null,true);
XMLSerializer serializer =
new XMLSerializer(new FileWriter(fileName),fmt);
serializer.asDOMSerializer().serialize(xmlDoc);
}
catch (Exception e){
e.printStackTrace();
}
}
}
This test code creates the XML database shown in Listing 19-13 . The createTable() method creates
the XML document and inserts the first record. Calling the updateTable() method results in the
insertion of the other records.
Listing 19-13: XML database created using XMLDBTest class
<?xml version="1.0"?>
<CustomerDB>
<CUSTOMER CUSTOMER_NUMBER="100">
<FIRST_NAME>Michael</FIRST_NAME>
<MI>A</MI>
<LAST_NAME>Corleone</LAST_NAME>
<STREET>123 Pine</STREET>
Search WWH ::




Custom Search