Chapter 15
626
actionPerformed() is where the button clicks are handled. Note the direct access to queryBean's
methods to purge the RDBMS of all records.
public void actionPerformed(ActionEvent evt) {
try {
if (evt.getSource() == purgeButton) {
databaseBean myUtil = new databaseBean();
myUtil.makeConnection();
myUtil.clean();
myUtil.takeDown();
}
if (evt.getSource() == inject1Button) {
parseAndAddRecords("data1.xml");
}
if (evt.getSource() == inject2Button) {
parseAndAddRecords("data2.xml");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main (String args[])
throws Exception {
TestTool myTT = new TestTool();
myTT.pack();
myTT.show();
}
}
While simple, this test tool illustrates the general framework that any XML-to-RDBMS conversion
program needs to have. It can serve as a starting point for coding modules that involve such
functionality. We have placed all the relevant files in a folder named projavaxml\Chapter15\tool\
To properly compile the tool, you need to make sure that you have the aelfred.jar file in your
classpath, together with sqlBean. You can compile the files from the folder they are in using the
following commands:
set classpath=<path_to>aelfred.jar;%classpath%
set classpath=<path_to>\vacserv\WEB-INF\classes;%classpath%
set classpath=.;%classpath%
javac TestTool.java
The first three lines add aelfred.jar, the com.wrox.pjxml package (substitute the relevant paths to
Ælfred and the com.wrx.pjxml package), and the current directory. The final command should then
compile the files. Here is the result on my system: