264 The XML Files: Develo pment of XML/XSL Applications Using WebS phere Studio
Figure 11-5 XMLToSQL
11.3.4 Modifying CustomerXSLServlet
The change to the CustomerXSLServlet is the doPost method of the servlet,
which enables storing new customer records in the database. Since doGet
returns the blank input form, we left as is. To achieve our target, we need to
perform the following to the CustomerXSLServlet:
򐂰Initialize XMLToSQL to work with the database.
򐂰Modify the doPost method to execute the insert.

Initializing the XMLToSQL class

We created separate initSQLProperties method to setup the property. Since we
use same property during this application running, we initialize this property in
the init method.
򐂰Add SqlProperties as a global variable:
private SQLProperties sqlProperties;
򐂰Add XMLToSQL as a global variable:
private XMLToSQL xml2sql;
򐂰Add initSQLProperties method (Example 11-1);
We recommend that you create a .properties file to keep the information to set
the SQLProperties.
򐂰In the init method, add a statement to invoke the initSQLProper ties method:
XML Document
SQL
Properties
-JdbcDriver
-LoginID
-Password
-JdbcServer
-Schema
-Action
Recurse

execute

Servlet instantiate
XMLToSQL