Package com.compomics.util.db
Class DBResultSet
java.lang.Object
javax.swing.table.AbstractTableModel
com.compomics.util.db.DBResultSet
- All Implemented Interfaces:
Serializable
,TableModel
public class DBResultSet extends AbstractTableModel
This class wraps a DB resultset in an 'offline' object.
- Author:
- Lennart Martens
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description DBResultSet()
Default 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 Type Method Description Class
getColumnClass(int columnIndex)
ReturnsObject.class
regardless ofcolumnIndex
.int
getColumnCount()
This method reports on the number of columns in the resultset.String
getColumnName(int column)
Returns a default name for the column using spreadsheet conventions: A, B, C, ...String[]
getColumnNames()
This method reports on all the columnn ames.Object[][]
getData()
This method reports on the data stored in the resultset.int
getRowCount()
This method reports on the number of rows in the resultset.Object
getValueAt(int rowIndex, int columnIndex)
Returns the value for the cell atcolumnIndex
androwIndex
.void
writeToCSVFile(Writer out, String aSeparator)
This method allows the caller to write the current dataset to the specified Writer.void
writeToHTMLTable(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 atcolumnIndex
androwIndex
.- 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.class
regardless ofcolumnIndex
.- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in 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. Ifcolumn
cannot be found, returns an empty string.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in 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.
-