david.gilbert wrote:My suggestion would be to look in the Javadocs for JFreeChart and find out which package the DefaultPieDataset class belongs to:
www(dot)jfree(dot)org/jfreechart/api/javadoc/org/jfree/data/general/DefaultPieDataset(dot)html
Thanks David. That worked great. However, I found out that the "quick" method won't work with what I have as a database connection, etc. So I had to switch over to a JDBCPieDataset. The problem I'm having now, is that it's claiming my "return type" is missing. My code is below. Given that most of it is copied out of the API documentation, I'm at a loss as to what could be wrong.
Then of course, the trick after creating all this is to toss it back through CeWolf somehow so that I can display it on my page.
Thanks,
-Terri
The error in the code is occurring at line #55.
Code: Select all
/*
* Created on Feb 12, 2009
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.prodash.action;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.Serializable;
import org.jfree.chart.labels.PieToolTipGenerator;
//import org.jfree.data.general.PieDataset;
import org.jfree.data.general.*;
import de.laures.cewolf.DatasetProducer;
import org.jfree.data.jdbc.JDBCPieDataset;
import com.bestchairs.BESPooledConnection;
/**
* This class produces a Dataset containing head counts for cities.
*/
public class GraphAction extends DefaultPieDataset {
/** For serialization. */
//static final long serialVersionUID = -8753216855496746108L;
/** The database connection. */
//Open Database Connection
BESPooledConnection BESConn = new BESPooledConnection();
Connection conn = BESConn.getConn();
//Define a query
String query="SELECT count(ememp#), emcity FROM wem GROUP BY emcity ";
/**
* Creates a new JDBCPieDataset using a pre-existing database connection.
* <P>
* The dataset is initialised with the supplied query.
*
* @param con the database connection.
* @param query the database connection.
*
* @throws SQLException if there is a problem executing the query.
*/
***!!!+++ERROR IS IN BELOW SECTION+++!!!****
public JDBCPieDataset(Connection conn, String query) throws SQLException {
conn.executeQuery(query);
return;
}
/**
* ExecuteQuery will attempt execute the query passed to it against the
* existing database connection. If no connection exists then no action
* is taken.
* The results from the query are extracted and cached locally, thus
* applying an upper limit on how many rows can be retrieved successfully.
*
* @param query the query to be executed.
*
* @throws SQLException if there is a problem executing the query.
*/
public void executeQuery(String query) throws SQLException {
executeQuery(conn, query);
}
/**
* ExecuteQuery will attempt execute the query passed to it against the
* existing database connection. If no connection exists then no action
* is taken.
* The results from the query are extracted and cached locally, thus
* applying an upper limit on how many rows can be retrieved successfully.
*
* @param query the query to be executed
* @param con the connection the query is to be executed against
*
* @throws SQLException if there is a problem executing the query.
*/
public void executeQuery(Connection conn, String query) throws SQLException {
Statement statement = null;
ResultSet resultSet = null;
try {
statement = conn.createStatement();
resultSet = statement.executeQuery(query);
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
if (columnCount != 2) {
throw new SQLException(
"Invalid sql generated. PieDataSet requires 2 columns only"
);
}
int columnType = metaData.getColumnType(2);
double value = Double.NaN;
while (resultSet.next()) {
Comparable key = resultSet.getString(1);
switch (columnType) {
case Types.NUMERIC:
case Types.REAL:
case Types.INTEGER:
case Types.DOUBLE:
case Types.FLOAT:
case Types.DECIMAL:
case Types.BIGINT:
value = resultSet.getDouble(2);
setValue(key, value);
break;
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
Timestamp date = resultSet.getTimestamp(2);
value = date.getTime();
setValue(key, value);
break;
default:
System.err.println(
"JDBCPieDataset - unknown data type"
);
break;
}
}
fireDatasetChanged();
}
finally {
if (resultSet != null) {
try {
resultSet.close();
}
catch (Exception e) {
System.err.println("JDBCPieDataset: swallowing exception.");
}
}
if (statement != null) {
try {
statement.close();
}
catch (Exception e) {
System.err.println("JDBCPieDataset: swallowing exception.");
}
}
}
}
}