Package not complete?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
TerriLyn
Posts: 3
Joined: Wed Feb 11, 2009 8:58 pm

Package not complete?

Post by TerriLyn » Wed Feb 11, 2009 9:48 pm

Good afternoon!

I am new to JFreeChart and having some problems. I'm trying to do a project in Websphere (Java Struts) and as I am new, I'm working my way through a tutorial I found online. (Though I am going to have to modify it for my own personal data.)

However, now that I have downloaded the two packages mentioned, both the Cewolf and Jfree, and copied the relevant information to my project and ensured it was on the classpath... I now find that the jar file seems to be incomplete, and I've even tried downloading a new jar file to no avail. The issue I'm having is that the import of org.jfree.data.* and org.jfree.chart* seem to be incomplete. I was getting errors that there were no references to items like the "DefaultPieDataset". So, I backed up and got it to trigger the auto complete, just to see that there wasn't a "DefaultPieDataset" in the package. (See image below.) I've even downloaded the required parts again to see if that fixed it, but it did not.

Does anyone have any idea why I'm having these issues? Did I miss something on the install?

Any help would be much appriciated!

Thanks,
-Terri

Code: Select all

Image is here, it wouldn't let me link it!

www(dot)flickr(dot)com/photos/40278235@N00/3272021845/sizes/o/

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Feb 12, 2009 9:07 am

My suggestion would be to look in the Javadocs for JFreeChart and find out which package the DefaultPieDataset class belongs to:

http://www.jfree.org/jfreechart/api/jav ... taset.html
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

TerriLyn
Posts: 3
Joined: Wed Feb 11, 2009 8:58 pm

Post by TerriLyn » Thu Feb 12, 2009 5:53 pm

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.");
                    }
                }
            }
        }
    
    
        
    }

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Thu Feb 12, 2009 6:18 pm

A constructor must be named exactly like the class in which it is defined. Go grab yourself a beginner's Java-Book, it will serve you well.

TerriLyn
Posts: 3
Joined: Wed Feb 11, 2009 8:58 pm

Post by TerriLyn » Thu Feb 12, 2009 6:24 pm

Taqua wrote:A constructor must be named exactly like the class in which it is defined. Go grab yourself a beginner's Java-Book, it will serve you well.
See, I get that. I just get lost when I'm trying to adapt someone else's code as to what needs to be changed at times. Especially when it doesn't resemble my usual flavor of code. So, could I maybe get a better hint? I mean, should I return then a GraphAction or what?

This doesn't seem to construct in the same manner I'm used to, that's all.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Post by paradoxoff » Thu Feb 12, 2009 6:48 pm

See, I get that. I just get lost when I'm trying to adapt someone else's code as to what needs to be changed at times. Especially when it doesn't resemble my usual flavor of code. So, could I maybe get a better hint? I mean, should I return then a GraphAction or what?
Is this hint better: You have a class GraphAction (wether it makes sense to name a class that extends a Dataset like that class is another story. To me the name does not sound at all like a "data container"). This class has a public method JDBCPieDataset(Connection conn, String query). This method cannot be the constructor, because it has a different name than the surrounding class. Thus it has to have a return type, at least void. But that is missing, too, and this is what the compiler complains about.

Locked