Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 82879 Details for
Bug 209679
Can't Resolve Custom Library Jar Added to Classpath
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Example component for library
RSTableModel.java (text/plain), 3.90 KB, created by
Worthy Sizemore
on 2007-11-14 10:03:43 EST
(
hide
)
Description:
Example component for library
Filename:
MIME Type:
Creator:
Worthy Sizemore
Created:
2007-11-14 10:03:43 EST
Size:
3.90 KB
patch
obsolete
>import java.sql.ResultSet; >import java.sql.ResultSetMetaData; >import javax.swing.table.AbstractTableModel; > >/** > * RSTableModel > * @author Worthy Sizemore > * @version November 9, 2007 > * > * Creates an <code>AbstractTableModel</code> designed specifically > * to take information from a <code>ResultSet</code> for > * display in a <code>JTable</code>. Calculations for data retrieval > * are based on the fact that a <code>JTable</code> starts counting its > * rows and columns from 0 while a <code>ResultSet</code> starts counting > * its records and fields from 1. > */ > >@SuppressWarnings("serial") >class RSTableModel extends AbstractTableModel >{ > /** The <code>ResultSetMetaData</code> for the passed <code>ResultSet</code> */ > private ResultSetMetaData metadata; > /** The number of records that will be displayed. */ > private int numberOfRows; > /** The number of columns that will be displayed. */ > private int numberOfColumns; > /** The records retrieved from the <code>ResultSet</code>. */ > private Object[][] data; > /** The passed <code>ResultSet</code> which provides the record data. */ > private ResultSet dataSource; > > > /** > * Parameterized constructor. Initializes all variables based on the > * passed <code>ResultSet</code>. > * > * @param rs <code>ResultSet</code> that is to be displayed in a table. > * @exception prints stack trace on any exception > */ > public RSTableModel(ResultSet rs) > { > try > { > dataSource = rs; > > metadata = dataSource.getMetaData(); > > dataSource.last(); > numberOfRows = dataSource.getRow(); > numberOfColumns = metadata.getColumnCount(); > } > catch(Exception e) > { > e.printStackTrace(); > } > } > > /** > * Retrieves how many columns are needed for the table. > * > * @return numberOfColumns > */ > public int getColumnCount() > { > return numberOfColumns; > } > > /** > * Retrieves how many rows are needed for the table. > * > * @return numberOfRows > */ > public int getRowCount() > { > return numberOfRows; > } > > /** > * Retrieves the value of a specific cell. > * > * @param row Row position of the cell > * @param col Column position of the cell > * @return value stored in that position or an empty > * <code>String</code>. > * @exception prints stack trace on any exception > */ > public Object getValueAt(int row, int col) > { > try > { > dataSource.absolute(row + 1); > return dataSource.getObject(col + 1); > } > catch (Exception e) > { > e.printStackTrace(); > } > > return ""; // If it fails, return empty object. > } > > /** > * Retrieves the name of the class type for a specific > * column. > * > * @param col Column whose class type needs to be retrieve. > * @return name of the column's class type or simply class Object > * @exception prints stack trace on any exception > */ > @SuppressWarnings("unchecked") > public Class getColumnClass(int col) > { > try > { > String classname = metadata.getColumnClassName(col + 1); > > return Class.forName(classname); > } > catch (Exception e) > { > e.printStackTrace(); > } > > return Object.class; > } > > /** > * Changes a value in a specific cell. This can be used > * to overwrite or even add to the table. > * > * @param value New cell value. > * @param row Row position of the cell to change. > * @param col Column position of the cell to change. > */ > public void setValueAt(Object value, int row, int col) > { > data[row][col] = value; > fireTableCellUpdated(row, col); > } > > /** > * Retrieves the field name for a column. > * > * @param col Column number whose field name needs retrieval. > * @return Column name if successful or an empty <code>String</code> if not. > * @exception prints stack trace on any exception > */ > public String getColumnName(int col) > { > try > { > return metadata.getColumnName(col + 1); > } > catch (Exception e) > { > e.printStackTrace(); > } > > return ""; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 209679
: 82879