.
<%
/*
This is an example of a data-driven chart JSP, using a vertical
resultset.The period above has to be there to prevent the
javascript popup.style error; the character can't be a space.
*/
/*
Includes:
java.util has the Hashtable object and certain other methods
java.sql has the data access objects
netcharts.server has the chart building objects
*/
%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%
/*
You have to do it this way, rather than netcharts.server.*, because
there are classes in the api package and util package that have the
same name. Importing 'em separate like this prevents class name
collision.
*/
%>
<%@ page import="netcharts.server.api.*" %>
<%@ page import="netcharts.server.util.*" %>
<%
/*
Unlike IIS VBScript, this variable *must* be declared and initialized
before calling the Footer.inc include, even if it's supposed to be
empty.
*/
String strPageName = "";
String strQuery = "Select substr(REGISTRATION_NO, 1, 2) " +
"as CallLetters, count(Registration_no) " +
"as TheCount from brg_airplanes " +
"Where prod_line_no > '770' And active_ind = 'Y' " +
"And Substr(Model_No, 1, 3) = '757' " +
"Group by substr(REGISTRATION_NO, 1, 2) " +
"Order by TheCount";
/*
GETTING THE DATA INTO THE NETCHARTS CHART OBJECT
================================================
The column names and data rows are first appended onto a string.
This string is then loaded into a hash table, where the key exactly
matches the key inside the CDX file. The resulting hash table can then
be passed to the NetCharts object. :)
*/
String strDriver = "oracle.jdbc.driver.OracleDriver";
String strURL = "jdbc:oracle:thin:@fremont.ca.boeing.com";
String strServer = "brgprodb";
String strPort = "1521";
String strUID = "userid";
String strPWD = "password";
String strCtype = "cursor";
String strSolution = "aaMMOChartsPre";
String strProject = "testbed";
String strCDX = "TEST_Chart_ByCode_Bridge.cdx";
String strConn = strURL + ":" + strPort + ":" + strServer;
/*
Try to open a connection to the data source
*/
Connection objConn = null;
try
{
Class.forName(strDriver);
objConn = java.sql.DriverManager.getConnection(strConn,strUID,strPWD);
}
catch(Exception e)
{
e.printStackTrace();
out.println("Couldn't connect: " + e.getMessage() + "");
}
/*
If we have an open connection, we can try to get the data and build
the chart
*/
Statement objStmt = objConn.createStatement();
try
{
if (objStmt.execute("CALL MMI.AUTHORIZE()"))
{
//This is required to access the BRIDGE system
}
// get the data and metadata
ResultSet objRS = objStmt.executeQuery(strQuery);
// initialize the local strings
String strColumns = "BarLabels = ";
String strRows = "DataSet1 = ";
/*
load the local strings with data. We have to do it like this
because the SQL Server driver we're using doesn't support cursor
movement methods. :(
*/
while(objRS.next())
{
strColumns = strColumns + "'" + objRS.getObject(1) + "',";
strRows = strRows + objRS.getObject(2) + ",";
}
strColumns = strColumns.substring(0, strColumns.length() - 1) + ";";
strRows = strRows.substring(0, strRows.length() - 1) + ";";
// We have the data locally; release the objects for GC
objRS.close();
objConn.close();
/*
load the local string into the Hashtable. In the CDX file, the
BarLabels and DataSet1 parameters should be replaced with the key
shown in the first parameter of the put method - in this case,
THEDATA.
*/
Hashtable objchartParams = new Hashtable();
objchartParams.put("THEMETADATA", strColumns);
objchartParams.put("THEDATA", strRows);
/*
Create a NetCharts object and load the Hashtable into it. The
NetCharts object parameter is the project name in the Development
console. Note the name of the CDX file that goes with this dataset.
*/
NSWebToolKit objTK = new NSWebToolKit(strSolution + "\\" + strProject);
String strChart = objTK.getChartAsImageAndMap
(
strCDX,
objchartParams,
request,
true
);
// We're done; display the chart
out.println(strChart);
}
catch(Exception e)
{
e.printStackTrace();
out.println("
Query Failed." + "\n\n" +
e.getMessage() + "");
}
%>
<%@ include file="../Footer.inc" %>