Package org.jfree.data
Class JDBCXYDataset
java.lang.Object
org.jfree.data.AbstractDataset
org.jfree.data.AbstractSeriesDataset
org.jfree.data.AbstractXYDataset
org.jfree.data.JDBCXYDataset
- All Implemented Interfaces:
ObjectInputValidation,Serializable,Cloneable,EventListener,Dataset,RangeInfo,SeriesChangeListener,SeriesDataset,TableXYDataset,XYDataset
public class JDBCXYDataset extends AbstractXYDataset implements XYDataset, TableXYDataset, RangeInfo
This class provides an
XYDataset implementation over a database JDBC
result set. The dataset is populated via a call to executeQuery with the
string sql query. The sql query must return at least two columns. The first
column will be the x-axis and remaining columns y-axis values. executeQuery
can be called a number of times. The database connection is read-only and no
write back facility exists.- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description JDBCXYDataset(String url, String driverName, String user, String password)Creates a new dataset (initially empty) and establishes a new database connection.JDBCXYDataset(Connection con)Creates a new dataset (initially empty) using the specified database connection.JDBCXYDataset(Connection con, String query)Creates a new dataset using the specified database connection, and populates it using data obtained with the supplied query. -
Method Summary
Modifier and Type Method Description voidclose()Close the database connectionvoidexecuteQuery(String query)ExecuteQuery will attempt execute the query passed to it against the existing database connection.voidexecuteQuery(Connection con, String query)ExecuteQuery will attempt execute the query passed to it against the provided database connection.intgetItemCount()Returns the number of items in all series.intgetItemCount(int seriesIndex)Returns the number of items in the specified series.intgetLegendItemCount()Returns the number of items that should be displayed in the legend.String[]getLegendItemLabels()Returns the legend item labels.NumbergetMaximumRangeValue()Returns the maximum data value in the dataset's range.NumbergetMinimumRangeValue()Returns the minimum data value in the dataset's range.intgetSeriesCount()Returns the number of series in the dataset.StringgetSeriesName(int seriesIndex)Returns the name of the specified series.RangegetValueRange()Returns the range of the values in this dataset's range (y-values).NumbergetXValue(int seriesIndex, int itemIndex)Returns the x-value for the specified series and item.NumbergetYValue(int seriesIndex, int itemIndex)Returns the y-value for the specified series and item.booleanisTimeSeries()Returnstrueif the dataset represents time series data, andfalseotherwise.voidsetTimeSeries(boolean timeSeries)Sets a flag that indicates whether or not the data represents a time series.Methods inherited from class org.jfree.data.AbstractXYDataset
getX, getYMethods inherited from class org.jfree.data.AbstractSeriesDataset
seriesChangedMethods inherited from class org.jfree.data.AbstractDataset
addChangeListener, clone, getGroup, removeChangeListener, setGroup, validateObjectMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jfree.data.Dataset
addChangeListener, getGroup, removeChangeListener, setGroup
-
Constructor Details
-
JDBCXYDataset
public JDBCXYDataset(String url, String driverName, String user, String password) throws SQLException, ClassNotFoundExceptionCreates a new dataset (initially empty) and establishes a new database connection.- Parameters:
url- URL of the database connection.driverName- the database driver class name.user- the database user.password- the database user's password.- Throws:
ClassNotFoundException- if the driver cannot be found.SQLException- if there is a problem connecting to the database.
-
JDBCXYDataset
Creates a new dataset (initially empty) using the specified database connection.- Parameters:
con- the database connection.- Throws:
SQLException- if there is a problem connecting to the database.
-
JDBCXYDataset
Creates a new dataset using the specified database connection, and populates it using data obtained with the supplied query.- Parameters:
con- the connection.query- the SQL query.- Throws:
SQLException- if there is a problem executing the query.
-
-
Method Details
-
isTimeSeries
public boolean isTimeSeries()Returnstrueif the dataset represents time series data, andfalseotherwise.- Returns:
- a boolean.
-
setTimeSeries
public void setTimeSeries(boolean timeSeries)Sets a flag that indicates whether or not the data represents a time series.- Parameters:
timeSeries- the new value of the flag.
-
executeQuery
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.- Parameters:
query- the query to be executed.- Throws:
SQLException- if there is a problem executing the query.
-
executeQuery
ExecuteQuery will attempt execute the query passed to it against the provided database connection. If connection is null 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.- Parameters:
query- the query to be executed.con- the connection the query is to be executed against.- Throws:
SQLException- if there is a problem executing the query.
-
getXValue
Returns the x-value for the specified series and item. The implementation is responsible for ensuring that the x-values are presented in ascending order. -
getYValue
Returns the y-value for the specified series and item. -
getItemCount
public int getItemCount(int seriesIndex)Returns the number of items in the specified series.- Specified by:
getItemCountin interfaceXYDataset- Parameters:
seriesIndex- The series (zero-based index).- Returns:
- The itemCount value
- See Also:
XYDataset
-
getItemCount
public int getItemCount()Returns the number of items in all series. This method is defined by theTableXYDatasetinterface.- Specified by:
getItemCountin interfaceTableXYDataset- Returns:
- The item count.
-
getSeriesCount
public int getSeriesCount()Returns the number of series in the dataset.- Specified by:
getSeriesCountin interfaceSeriesDataset- Specified by:
getSeriesCountin classAbstractSeriesDataset- Returns:
- The seriesCount value
- See Also:
XYDataset,Dataset
-
getSeriesName
Returns the name of the specified series.- Specified by:
getSeriesNamein interfaceSeriesDataset- Specified by:
getSeriesNamein classAbstractSeriesDataset- Parameters:
seriesIndex- The series (zero-based index).- Returns:
- The seriesName value
- See Also:
XYDataset,Dataset
-
getLegendItemCount
public int getLegendItemCount()Returns the number of items that should be displayed in the legend.- Returns:
- The legendItemCount value
-
getLegendItemLabels
Returns the legend item labels.- Returns:
- The legend item labels.
-
getMinimumRangeValue
Returns the minimum data value in the dataset's range.- Specified by:
getMinimumRangeValuein interfaceRangeInfo- Returns:
- The minimum value.
- See Also:
RangeInfo
-
getMaximumRangeValue
Returns the maximum data value in the dataset's range.- Specified by:
getMaximumRangeValuein interfaceRangeInfo- Returns:
- The maximum value.
- See Also:
RangeInfo
-
close
public void close()Close the database connection -
getValueRange
Returns the range of the values in this dataset's range (y-values).- Specified by:
getValueRangein interfaceRangeInfo- Returns:
- The range.
-