the applet and servlet can be set to acquire data from
a database ( or multiple databases ) by utilizing a
server side script or process.
In the previous section ( Connecting
the Graph to a Server Process. ) We saw how to connect
both the applet and servlet to a server side process.
The server side process can be written in any language
of your choice and as such can be written to acquire
data from any data source desired (databases, other
processes, files etc.).
Graphing Software provides several methods by which
data can be acquired from databases. For a full discussion
on the various methods and Template Scripts please
we will demonstrate how to create a Java Servlet which
acquires data from a single database and present the
data in the correct format to either the graph applet
or graph servlet.
is designed to retrieve product sales data from a MySQL
database, from a table with the following structure,
Name : SalesBar
servlet will pick out the sales figures for three products
( ProductX, ProductY and ProductZ) and return the data
in the correct format for the graph.
method is as follows,
Set the output characteristics for the return data
Establish the database connection
Build the query statement and retrieve the database
Process the database records and return the Data
All finished so close the database connection
full servlet code is contained in the DatabaseServletBar
here to view the code).
you will see from the code the servlet connects to the
database via JDBC and as such it is essential to have
the correct JDBC drivers for your database. ( For further
information on JDBC drivers please see http://industry.java.sun.com/products/JDBC/drivers