2D / 3D Horizontal Bar Graph - Tutorials

Quick Start Tutorials - Direct Database Connection

The servlet form of the graphing software provides a method by which the graphing function can bind directly to a database.

Method Outline
The graphing <IMG> tag is added to an html page but rather than supplying a "data" parameter for the servlet a
"dataDB" parameter is specified. The dataDB parameter points to a file which contains the database connection details
(DB name, Username and Password) and an SQL Statement for each series of data.

At page view time the Servlet will:-

read the database info file

connect to the database

extract the data

construct the graph image and dynamically add to the HTML page

Note: This method may only be applied to the Servlet form of the graphing software.

Implementation
To implement this method perform the following 5 steps,

Step 1 - Construct
the Database info file
The database info file should contain the information required to create a connection to the database and the SQL
statements for each series of data.

Database Connection InfoThere are 4 pieces of info required to make the Database
Connection. These are specified with the following parameters,

Database:
Driver:
User:
Password:

Database: - This is the database connection path and name.
eg. If you have a MySQL database called Sales you may have,

Database: jdbc:mysql://localhost/Sales

Driver: This is the location of the JDBC Driver for your database system. In order for the graphing servlet
to connect to your database it is vital that you have the correct JDBC driver set up and configured for you system.
For further information on JDBC database drivers please
click here.

User: The username which the graphing servlet will use to connect to the database

Password: The database password for the Username specified.

Series SQL Statements
For each series of data an SQL Statement should be specified. The graph servlet will execute each statement and take
the first data item of each record returned as the value for that data item. For instance if you have a table which
holds monthly sales figures for 2 products X and Y then your statements may look like,

series1: Select Value from SalesBar where Year=2004 and Product='X' ORDER
BY Month

series2: Select Value from SalesBar where Year=2004 and Product='Y' ORDER BY Month

If 6 records are returned for each record set this would mean that there are 6 data points for each series of data.

Upload the Database Info file (created in Step 1) to the directory
specified in the "dataDB" parameter of the <IMG> tag created in step 2.

Step 5 - Add the
graphing class files to your Servlet Engine.
The final step is to install the graphing class files in your Servlet Engine.

Place the following class files and the 'encoder' directory in
your Servlet Engine's class file directory. For Tomcat this is usually /WEB-INF/classes/ and for the default setup
of the JSDK environment this is the /examples/ directory.

hbarcharts.class
HbarchartServlet.class
encoder

(these classes & directory can be found in the ./Servlet
directory ).

For further Information on this please see the following section
in the Documentation