The applet and servlet can be set to acquire data from a database ( or multiple
databases ) by utilizing a server side script or process.
Such a server side process can be written any language including PHP,JSP,ASP, Java Servlet, Perl etc. Here
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 DatabaseServletPie
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