Class JDBCXYDataset

All Implemented Interfaces:
ObjectInputValidation, Serializable, Cloneable, EventListener, Dataset, SeriesChangeListener, SeriesDataset, RangeInfo, TableXYDataset, XYDataset

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:
  • Constructor Details

    • JDBCXYDataset

      public JDBCXYDataset(String url, String driverName, String user, String password) throws SQLException, ClassNotFoundException
      Creates 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

      public JDBCXYDataset(Connection con, String query) throws SQLException
      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()
      Returns true if the dataset represents time series data, and false otherwise.
      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

      public void executeQuery(String query) throws SQLException
      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

      public void executeQuery(Connection con, String query) throws SQLException
      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:
      con - the connection the query is to be executed against.
      query - the query to be executed.
      Throws:
      SQLException - if there is a problem executing the query.
    • getX

      public Number getX(int seriesIndex, int itemIndex)
      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.
      Specified by:
      getX in interface XYDataset
      Parameters:
      seriesIndex - the series (zero-based index).
      itemIndex - the item (zero-based index).
      Returns:
      The x-value
      See Also:
    • getY

      public Number getY(int seriesIndex, int itemIndex)
      Returns the y-value for the specified series and item.
      Specified by:
      getY in interface XYDataset
      Parameters:
      seriesIndex - the series (zero-based index).
      itemIndex - the item (zero-based index).
      Returns:
      The yValue value
      See Also:
    • getItemCount

      public int getItemCount(int seriesIndex)
      Returns the number of items in the specified series.
      Specified by:
      getItemCount in interface XYDataset
      Parameters:
      seriesIndex - the series (zero-based index).
      Returns:
      The itemCount value
      See Also:
    • getItemCount

      public int getItemCount()
      Returns the number of items in all series. This method is defined by the TableXYDataset interface.
      Specified by:
      getItemCount in interface TableXYDataset
      Returns:
      The item count.
    • getSeriesCount

      public int getSeriesCount()
      Returns the number of series in the dataset.
      Specified by:
      getSeriesCount in interface SeriesDataset
      Specified by:
      getSeriesCount in class AbstractSeriesDataset
      Returns:
      The seriesCount value
      See Also:
    • getSeriesKey

      public Comparable getSeriesKey(int seriesIndex)
      Returns the key for the specified series.
      Specified by:
      getSeriesKey in interface SeriesDataset
      Specified by:
      getSeriesKey in class AbstractSeriesDataset
      Parameters:
      seriesIndex - the series (zero-based index).
      Returns:
      The seriesName value
      See Also:
    • close

      public void close()
      Close the database connection
    • getRangeLowerBound

      public double getRangeLowerBound(boolean includeInterval)
      Returns the minimum y-value in the dataset.
      Specified by:
      getRangeLowerBound in interface RangeInfo
      Parameters:
      includeInterval - a flag that determines whether or not the y-interval is taken into account.
      Returns:
      The minimum value.
    • getRangeUpperBound

      public double getRangeUpperBound(boolean includeInterval)
      Returns the maximum y-value in the dataset.
      Specified by:
      getRangeUpperBound in interface RangeInfo
      Parameters:
      includeInterval - a flag that determines whether or not the y-interval is taken into account.
      Returns:
      The maximum value.
    • getRangeBounds

      public Range getRangeBounds(boolean includeInterval)
      Returns the range of the values in this dataset's range.
      Specified by:
      getRangeBounds in interface RangeInfo
      Parameters:
      includeInterval - a flag that determines whether or not the y-interval is taken into account.
      Returns:
      The range.