Package org.jfree.data.jdbc
Class JDBCCategoryDataset
- java.lang.Object
-
- org.jfree.data.general.AbstractDataset
-
- org.jfree.data.category.DefaultCategoryDataset
-
- org.jfree.data.jdbc.JDBCCategoryDataset
-
- All Implemented Interfaces:
java.io.ObjectInputValidation,java.io.Serializable,java.lang.Cloneable,PublicCloneable,CategoryDataset,Dataset,KeyedValues2D,Values2D
public class JDBCCategoryDataset extends DefaultCategoryDataset
ACategoryDatasetimplementation over a database JDBC result set. The dataset is populated via a call toexecuteQuery(String)with the string SQL query. The SQL query must return at least two columns. The first column will be the category name and remaining columns values (each column represents a series). Subsequent calls toexecuteQuery(String)will refresh the dataset.The database connection is read-only and no write back facility exists.
NOTE: Many people have found this class too restrictive in general use. For the greatest flexibility, please consider writing your own code to read data from a
ResultSetand populate aDefaultCategoryDatasetdirectly.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.sql.ConnectionconnectionThe database connection.(package private) static longserialVersionUIDFor serialization.private booleantransposeA flag the controls whether or not the table is transposed.
-
Constructor Summary
Constructors Constructor Description JDBCCategoryDataset(java.lang.String url, java.lang.String driverName, java.lang.String user, java.lang.String passwd)Creates a new dataset with a database connection.JDBCCategoryDataset(java.sql.Connection connection)Create a new dataset with the given database connection.JDBCCategoryDataset(java.sql.Connection connection, java.lang.String query)Creates a new dataset with the given database connection, and executes the supplied query to populate the dataset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecuteQuery(java.lang.String query)Populates the dataset by executing the supplied query against the existing database connection.voidexecuteQuery(java.sql.Connection con, java.lang.String query)Populates the dataset by executing the supplied query against the existing database connection.booleangetTranspose()Returns a flag that controls whether or not the table values are transposed when added to the dataset.voidsetTranspose(boolean transpose)Sets a flag that controls whether or not the table values are transposed when added to the dataset.-
Methods inherited from class org.jfree.data.category.DefaultCategoryDataset
addValue, addValue, clear, clone, equals, getColumnCount, getColumnIndex, getColumnKey, getColumnKeys, getRowCount, getRowIndex, getRowKey, getRowKeys, getValue, getValue, hashCode, incrementValue, removeColumn, removeColumn, removeRow, removeRow, removeValue, setValue, setValue
-
Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, canEqual, fireDatasetChanged, getGroup, getNotify, hasListener, notifyListeners, removeChangeListener, setGroup, setNotify, validateObject
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jfree.data.general.Dataset
addChangeListener, getGroup, removeChangeListener, setGroup
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
connection
private transient java.sql.Connection connection
The database connection.
-
transpose
private boolean transpose
A flag the controls whether or not the table is transposed. The default is 'true' because this provides the behaviour described in the documentation.
-
-
Constructor Detail
-
JDBCCategoryDataset
public JDBCCategoryDataset(java.lang.String url, java.lang.String driverName, java.lang.String user, java.lang.String passwd) throws java.lang.ClassNotFoundException, java.sql.SQLExceptionCreates a new dataset with a database connection.- Parameters:
url- the URL of the database connection.driverName- the database driver class name.user- the database user.passwd- the database user's password.- Throws:
java.lang.ClassNotFoundException- if the driver cannot be found.java.sql.SQLException- if there is an error obtaining a connection to the database.
-
JDBCCategoryDataset
public JDBCCategoryDataset(java.sql.Connection connection)
Create a new dataset with the given database connection.- Parameters:
connection- the database connection.
-
JDBCCategoryDataset
public JDBCCategoryDataset(java.sql.Connection connection, java.lang.String query) throws java.sql.SQLExceptionCreates a new dataset with the given database connection, and executes the supplied query to populate the dataset.- Parameters:
connection- the connection.query- the query.- Throws:
java.sql.SQLException- if there is a problem executing the query.
-
-
Method Detail
-
getTranspose
public boolean getTranspose()
Returns a flag that controls whether or not the table values are transposed when added to the dataset.- Returns:
- A boolean.
-
setTranspose
public void setTranspose(boolean transpose)
Sets a flag that controls whether or not the table values are transposed when added to the dataset.- Parameters:
transpose- the flag.
-
executeQuery
public void executeQuery(java.lang.String query) throws java.sql.SQLExceptionPopulates the dataset by executing the supplied query 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.- Throws:
java.sql.SQLException- if there is a problem executing the query.
-
executeQuery
public void executeQuery(java.sql.Connection con, java.lang.String query) throws java.sql.SQLExceptionPopulates the dataset by executing the supplied query 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:
con- the connection.query- the query.- Throws:
java.sql.SQLException- if there is a problem executing the query.
-
-