home *** CD-ROM | disk | FTP | other *** search
- <%@ page import="java.sql.*" %>
- <%@ page import="java.util.*" %>
- <%@ page import="java.lang.*" %>
- <%@ page import="java.io.*" %>
-
- <%
- //-------------------------------------------------------------------
- //
- // This simple JSP is designed to demonstrate how a JSP can be used
- // to retrieve data from a database and construct a dynamic page
- // containing the graphing applet.
- //
- // You may freely copy and modify this script to suite your own
- // requirements.
- //
- // For further information visit,
- // http://www.jpowered.com/pie_chart/
- //
- //-------------------------------------------------------------------
-
- // Initialise and set variables
- String url = "jdbc:MySQL:///TESTDB"; // URL specifying the JDBC connection to a MySQL database TESTDB.
- Connection con = null; // Database connection object
- Statement stmt = null; // Statement String
- String query; // Query String
- int datacount;
- ResultSet srs1 = null;
- ResultSet srs2 = null;
-
- // Establish the database connection
- try {
- // Connect to TESTDB
- Class.forName("org.gjt.mm.mysql.Driver");
- con = DriverManager.getConnection (url,"[DB Username]","[DB Password]");
- stmt = con.createStatement();
-
- } // End try
-
-
- // Error handling
- catch(ClassNotFoundException e) {out.println("Could not load database driver: " + e.getMessage());}
- catch(SQLException e) {out.println("SQLException caught: " + e.getMessage());}
-
-
-
- %>
-
-
- <html>
-
- <head>
- <title>3D Pie Chart</title>
- </head>
-
- <body>
- <applet code='PiechartApplet.class' archive='Piechart.jar' width='500' height='420'>
- <!-- Start Up Parameters -->
- <PARAM name='LOADINGMESSAGE' value='Pie Chart Loading - Please Wait.'> <!-- Message to be displayed on Startup -->
- <PARAM name='STEXTCOLOR' value='0,0,100'> <!-- Message Text Color-->
- <PARAM name='STARTUPCOLOR' value='255,255,255'> <!-- Applet Background color -->
-
- <!-- Property file -->
- <PARAM name='chartproperties' value='piepropsdb.txt'>
-
- <!-- Chart Data -->
- <%
- try {
- // Performing SQL query for Product X
- query = "Select Value from SalesBar where Year=2004 and Product='X' ORDER BY Month";
- srs1 = stmt.executeQuery(query);
-
- // Write out the data for Series 1
- datacount = 1;
- while (srs1.next()) {
- out.println("<param name='data"+datacount+"series1' value='"+srs1.getString("Value")+"'>\n");
- datacount++;
- }
-
- // Performing SQL query for Product Y
- query = "Select Value from SalesBar where Year=2004 and Product='Y' ORDER BY Month";
- srs2 = stmt.executeQuery(query);
-
- // Write out the data for Series 2
- datacount = 1;
- while (srs2.next()) {
- out.println("<param name='data"+datacount+"series2' value='"+srs2.getString("Value")+"'>\n");
- datacount++;
- }
-
- }
-
- // Error handling
- catch(SQLException e) {out.println("SQLException caught: " + e.getMessage());}
-
- // All finished so close the database connection
- finally {
- try {if (con != null) con.close();}
- catch (SQLException e) {}
- }
-
- %>
-
-
- </applet>
-
-
- </body>
- </html>