import java.sql.*;
import java.lang.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LineAppletDB extends HttpServlet {
//
// This simple servlet is designed to demonstrate how a servlet can be used
// to retrieve data from a database and return the data in the correct format
// to either the graphing applet or servlet.
//
// You may freely copy and modify this script to suite your own
// requirements.
//
// For further information visit,
// http://www.jpowered.com/line_graph/index.htm
//
//-----------------------------------------------------------------------------
// 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;
//-----------------------------------------------------------------------------
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// Set the output characterics for the return data
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
// 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();
// Construct HTML page containing Bar Chart Applet
out.println("\n");
out.println("
\n");
out.println("Line Graph\n");
out.println("\n");
out.println("\n");
out.println("\n");
out.println(" \n");
out.println("\n");
out.println("\n");
} // 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());}
// All finished so close the database connection
finally {
try {if (con != null) con.close();}
catch (SQLException e) {}
}
} // End doGet
//-----------------------------------------------------------------------------
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {doGet(request, response);}
//-----------------------------------------------------------------------------
} // End class