Package com.compomics.util.db
Class DBResultSet
java.lang.Object
javax.swing.table.AbstractTableModel
com.compomics.util.db.DBResultSet
- All Implemented Interfaces:
Serializable,TableModel
This class wraps a DB resultset in an 'offline' object.
- Author:
- Lennart Martens
- See Also:
-
Field Summary
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, just creates an empty resultset.DBResultSet(ResultSet aRS) This constructor takes a ResultSet from which the data is read.DBResultSet(ResultSet aRS, boolean aNullReplace) This constructor takes a ResultSet from which the data is read. -
Method Summary
Modifier and TypeMethodDescriptiongetColumnClass(int columnIndex) ReturnsObject.classregardless ofcolumnIndex.intThis method reports on the number of columns in the resultset.getColumnName(int column) Returns a default name for the column using spreadsheet conventions: A, B, C, ...String[]This method reports on all the columnn ames.Object[][]getData()This method reports on the data stored in the resultset.intThis method reports on the number of rows in the resultset.getValueAt(int rowIndex, int columnIndex) Returns the value for the cell atcolumnIndexandrowIndex.voidwriteToCSVFile(Writer out, String aSeparator) This method allows the caller to write the current dataset to the specified Writer.voidwriteToHTMLTable(Writer out, int aBorderstyle) This method allows the caller to write the current dataset to the specified Writer.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
-
Constructor Details
-
DBResultSet
public DBResultSet()Default constructor, just creates an empty resultset. -
DBResultSet
This constructor takes a ResultSet from which the data is read. This ResultSet will not be closed by this constructor, so it remains available and the closing is up to the caller! Nullreplace is FALSE for this constructor!- Parameters:
aRS- ResultSet from which to read the data. Closing the ResultSet is up to the caller!!- Throws:
SQLException- whenever reading the resultset failed.
-
DBResultSet
This constructor takes a ResultSet from which the data is read. This ResultSet will not be closed by this constructor, so it remains available and the closing is up to the caller! Notice that the null replace flag allows you to replace 'null' values returned by the DB to the String "(null)".- Parameters:
aRS- ResultSet from which to read the data. Closing the ResultSet is up to the caller!!aNullReplace- boolean to indicate whether 'null' values returned by the DB should be converted into "(null)" Strings ('true') or not ('false').- Throws:
SQLException- whenever reading the resultset failed.
-
-
Method Details
-
getColumnNames
This method reports on all the columnn ames.- Returns:
- String[] with all the column names.
-
getData
This method reports on the data stored in the resultset.- Returns:
- Object[][] with the data.
-
getColumnCount
public int getColumnCount()This method reports on the number of columns in the resultset.- Returns:
- int with the columncount.
-
getRowCount
public int getRowCount()This method reports on the number of rows in the resultset.- Returns:
- int with the rowcount.
-
getValueAt
Returns the value for the cell atcolumnIndexandrowIndex.- Parameters:
rowIndex- the row whose value is to be queriedcolumnIndex- the column whose value is to be queried- Returns:
- the value Object at the specified cell
-
getColumnClass
ReturnsObject.classregardless ofcolumnIndex.- Specified by:
getColumnClassin interfaceTableModel- Overrides:
getColumnClassin classAbstractTableModel- Parameters:
columnIndex- the column being queried- Returns:
- the Object.class
-
getColumnName
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc. Ifcolumncannot be found, returns an empty string.- Specified by:
getColumnNamein interfaceTableModel- Overrides:
getColumnNamein classAbstractTableModel- Parameters:
column- the column being queried- Returns:
- a string containing the default name of
column
-
writeToCSVFile
This method allows the caller to write the current dataset to the specified Writer. Note that flushing and closing the writer is up to the caller.- Parameters:
out- Writer to print to. Note that flushing and closing this writer is up to the caller.aSeparator- String with the separator character(s) to use.- Throws:
IOException- when something goes wrong.
-
writeToHTMLTable
This method allows the caller to write the current dataset to the specified Writer. Note that flushing and closing the writer is up to the caller.- Parameters:
out- Writer to print to. Note that flushing and closing this writer is up to the caller.aBorderstyle- int with the HTML table border tag style for the table.- Throws:
IOException- when something goes wrong.
-