FileDocCategorySizeDatePackage
RowSetModel.javaAPI DocExample5899Tue Aug 22 21:31:02 BST 2000com.imaginary.swing

RowSetModel

public class RowSetModel extends AbstractTableModel implements RowSetListener

Fields Summary
private RowSet
rowSet
Constructors Summary
public RowSetModel(RowSet set)

    
       
        super();
        rowSet = set;
        rowSet.addRowSetListener(this);
    
Methods Summary
public voidcursorMoved(javax.sql.RowSetEvent event)

    
public java.lang.ClassgetColumnClass(int column)

        String cname;
        int type;
	
        try {
            ResultSetMetaData meta = rowSet.getMetaData();

            if( meta == null ) {
                return null;
            }
            type = meta.getColumnType(column+1);
        }
        catch( SQLException e ) {
            e.printStackTrace();
            return super.getColumnClass(column);
        }
        switch( type ) {
        case Types.BIT:
            {
                cname = "java.lang.Boolean";
                break;
            }
        case Types.TINYINT:
            {
                cname = "java.lang.Byte";
                break;
            }
        case Types.SMALLINT:
            {
                cname = "java.lang.Short";
                break;
            }
        case Types.INTEGER:
            {
                cname = "java.lang.Integer";
                break;
            }
        case Types.BIGINT:
            {
                cname = "java.lang.Long";
                break;
            }
        case Types.FLOAT: case Types.REAL:
            {
                cname = "java.lang.Float";
                break;
            }
        case Types.DOUBLE:
            {
                cname = "java.lang.Double";
                break;
            }
        case Types.NUMERIC:
            {
                cname = "java.lang.Number";
                break;
            }
        case Types.DECIMAL:
            {
                cname = "java.math.BigDecimal";
                break;
            }
        case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR:
            {
                cname = "java.lang.String";
                break;
            }
        case Types.DATE:
            {
                cname = "java.sql.Date";
                break;
            }
        case Types.TIME:
            {
                cname = "java.sql.Time";
                break;
            }
        case Types.TIMESTAMP:
            {
                cname = "java.sql.Timestamp";
                break;
            }
        case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY:
            {
                cname = "byte[]";
                break;
            }
        case Types.OTHER: case Types.JAVA_OBJECT:
            {
                cname = "java.lang.Object";
                break;
            }
        case Types.CLOB:
            {
                cname = "java.sql.Clob";
                break;
            }
        case Types.BLOB:
            {
                cname = "java.ssql.Blob";
                break;
            }
        case Types.REF:
            {
                cname = "java.sql.Ref";
                break;
            }
        case Types.STRUCT:
            {
                cname = "java.sql.Struct";
                break;
            }
        default:
            {
                return super.getColumnClass(column);
            }
        }
        try {
            return Class.forName(cname);
        }
        catch( Exception e ) {
            e.printStackTrace();
            return super.getColumnClass(column);
        }
    
public intgetColumnCount()

        try {
            ResultSetMetaData meta = rowSet.getMetaData();

            if( meta == null ) {
                return 0;
            }
            return meta.getColumnCount();
        }
        catch( SQLException e ) {
            return 0;
        }
    
public java.lang.StringgetColumnName(int col)

        try {
            ResultSetMetaData meta = rowSet.getMetaData();

            if( meta == null ) {
                return null;
            }
            return meta.getColumnName(col+1);
        }
        catch( SQLException e ) {
            return "Error";
        }
    
public intgetRowCount()

        try {
            if( rowSet.last() ) {
                return (rowSet.getRow());
            }
            else {
                return 0;
            }
        }
        catch( SQLException e ) {
            return 0;
        }
    
public java.lang.ObjectgetValueAt(int row, int col)

        try {
            if( !rowSet.absolute(row+1) ) {
                return null;
            }
            return rowSet.getObject(col+1);
        }
        catch( SQLException e ) {
            return null;
        }
    
public voidrowChanged(javax.sql.RowSetEvent event)

        try {
            int row = rowSet.getRow();
            
            if( rowSet.rowDeleted() ) {
                fireTableRowsDeleted(row, row);
            }
            else if( rowSet.rowInserted() ) {
                fireTableRowsInserted(row, row);
            }
            else if( rowSet.rowUpdated() ) {
                fireTableRowsUpdated(row, row);
            }
        }
        catch( SQLException e ) {
        }
    
public voidrowSetChanged(javax.sql.RowSetEvent event)

        fireTableStructureChanged();
    
public voidsetValueAt(java.lang.Object value, int row, int column)

        try {
            if( !rowSet.absolute(row+1) ) {
                return;
            }
            rowSet.updateObject(column+1, value);
        }
        catch( SQLException e ) {
        }