StatBean Name: JdbcDataSource

Purpose: Reads data from a database by issuing a SQL query and saves the results in an invisible rectangular data table.

Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
jdbcColumnsStringThe columns names to be read, or "*" to read all columns.Any string."*"
jdbcDriverClassStringThe jdbc driver class to be used.Any string."sun.jdbc.odbc.JdbcOdbcDriver"
jdbcPasswordStringThe password associated with the user name.Any string.""
jdbcSchemaStringThe schema of the table to be read.Any string.""
jdbcSelectionStringA string used after the WHERE in a SQL query to select a subset of the records.Any string.""
jdbcTableStringThe name of the table to be read.Any string.""
jdbcURLStringThe URL of the database to be read.Any string."jdbc:odbc:dsname"
jdbcUsernameStringThe user name used to access the database.Any string.""
missingValueCodedoubleA numeric value used to represent missing values in the file to be read.Any numeric value.-32768.0

Other Public Methods
NameDescriptionArgumentsReturn Value
int getMaxRows()Gets the number of rows which were read.None.Number of rows.
int getMaxColumns()Gets the number of columns which were read.None.Number of columns.
boolean readData()Causes the data to be read and all listeners notified.None.true if data is read successfully

Other properties are inherited from the java.awt.Object class and from the general StatDataSource class.

Code Sample

//create the JdbcDataSource bean
JdbcDataSource jdbcDataSource1 = new JdbcDataSource();

//create a bean to display the data
DataDisplayTable dataDisplayTable1 = new DataDisplayTable();

//set the database name to be read
jdbcDataSource1.setJdbcURL("jdbc:odbc:Northwind");

//set the name of the table in the database
jdbcDataSource1.setJdbcTable("Employees");

//set the column names to be read
jdbcDataSource1.setJdbcColumns("City,EmployeeID,BirthDate");

//make the data table a listener for changes in the jdbcDataSource bean
jdbcDataSource1.addDataChangeListener(dataDisplayTable1.listenerForDataChange);

//instruct the jdbcDataSource bean to read the file
jdbcDataSource1.readData();