Example usage for java.sql ResultSet getByte

List of usage examples for java.sql ResultSet getByte

Introduction

In this page you can find the example usage for java.sql ResultSet getByte.

Prototype

byte getByte(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a byte in the Java programming language.

Usage

From source file:edu.ku.brc.specify.tasks.RecordSetTask.java

public void initialize() {
    if (!isInitialized) {
        super.initialize(); // sets isInitialized to false

        // Register all Tables as being able to be saved in a RecordSet
        // Although some system tables we may not want, they won't be searchable anyway.
        for (DBTableInfo ti : DBTableIdMgr.getInstance().getTables()) {
            ContextMgr.registerService(1, ti.getTitle(), ti.getTableId(),
                    new CommandAction(RECORD_SET, SAVE_RECORDSET), this, RECORD_SET,
                    getResourceString("CreateRecordSetTT"));
        }/*from w ww.j a va 2 s .c o  m*/

        //navBox = new DroppableNavBox(title, RECORDSET_FLAVOR, RECORD_SET, SAVE_RECORDSET);
        navBox = new NavBox(title);

        // TODO RELEASE Search for the the users or group's RecordSets!
        //List<?> recordSets = session.getDataList("FROM RecordSet where type = 0");
        SpecifyUser spUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);

        //SQLExecutionProcessor sqlProc = new SQ
        Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);

        String sqlStr = "SELECT rs.RecordSetID, Type, rs.Name, TableID, rs.Remarks FROM recordset as rs INNER JOIN specifyuser ON rs.SpecifyUserID = specifyuser.SpecifyUserID"
                + " WHERE type = 0 AND specifyuser.specifyUserID = " + spUser.getId()
                + " AND CollectionMemberID = " + collection.getId();

        Connection connection = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            connection = DBConnection.getInstance().createConnection();
            stmt = connection.createStatement();
            rs = stmt.executeQuery(sqlStr);

            while (rs.next()) {
                int dbTableId = rs.getInt(4);
                DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoById(dbTableId);
                RecordSetProxy rsProxy = new RecordSetProxy(rs.getInt(1), rs.getByte(2), rs.getString(3),
                        dbTableId, rs.getString(5), tableInfo.getClassObj());
                addToNavBox(rsProxy);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(RecordSetTask.class, ex);

        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
                if (connection != null) {
                    connection.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(RecordSetTask.class, e);
            }
        }

        /*for (Object row : rows)
        {
        Object[] data = (Object[])row;
                
        Integer     dbTableId = (Integer)data[1];
        DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoById(dbTableId);
        RecordSetProxy rsProxy = new RecordSetProxy((Integer)data[0],
                                                    (Byte)data[1],
                                                    (String)data[1],
                                                    dbTableId,
                                                    tableInfo.getClassObj(),
                                                    null);
        addToNavBox(rsProxy);*/

        /*RecordSetIFace recordSet = (RecordSetIFace)iter.next();
                
        recordSet.getItems(); // loads all lazy object 
                              // TODO Probably don't want to do this defer it to later when they are used.
        session.evict(recordSet);
                
        addToNavBox(recordSet);
        (*/
        //}
        navBoxes.add(navBox);
        //session.close();

    }
}

From source file:org.openiot.gsn.wrappers.TetraedreFluoWrapper.java

public void run() {
    DataEnumerator data;/* w ww .jav a  2s.c  om*/

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
    }

    Connection conn = null;
    ResultSet resultSet = null;

    while (isActive()) {
        try {
            conn = sm.getConnection();
            StringBuilder query = new StringBuilder("select * from ").append(table_name)
                    .append(" where physical_input=").append(physical_input).append(" AND timestamp*1000 > "
                            + latest_timed + "  order by timestamp limit 0," + buffer_size);

            resultSet = sm.executeQueryWithResultSet(query, conn);

            //logger.debug(query);

            while (resultSet.next()) {
                Serializable[] output = new Serializable[this.getOutputFormat().length];

                //long pk = resultSet.getLong(1);
                long timed = resultSet.getLong(3) * 1000;

                //logger.warn("pk => "+ pk);
                //logger.warn("timed => "+ timed);

                for (int i = 0; i < dataFieldsLength; i++) {

                    switch (dataFieldTypes[i]) {
                    case DataTypes.VARCHAR:
                    case DataTypes.CHAR:
                        output[i] = resultSet.getString(i + 1);
                        break;
                    case DataTypes.INTEGER:
                        output[i] = resultSet.getInt(i + 1);
                        break;
                    case DataTypes.TINYINT:
                        output[i] = resultSet.getByte(i + 1);
                        break;
                    case DataTypes.SMALLINT:
                        output[i] = resultSet.getShort(i + 1);
                        break;
                    case DataTypes.DOUBLE:
                        output[i] = resultSet.getDouble(i + 1);
                        break;
                    case DataTypes.BIGINT:
                        output[i] = resultSet.getLong(i + 1);
                        break;
                    case DataTypes.BINARY:
                        output[i] = resultSet.getBytes(i + 1);
                        break;
                    }
                    //logger.warn(i+" (type: "+dataFieldTypes[i]+" ) => "+output[i]);
                }

                StreamElement se = new StreamElement(dataFieldNames, dataFieldTypes, output, timed);
                latest_timed = se.getTimeStamp();

                //logger.warn(" Latest => " + latest_timed);

                this.postStreamElement(se);

                updateCheckPointFile(latest_timed);

                //logger.warn(se);
            }

        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        } catch (SQLException e) {
            logger.error(e.getMessage(), e);
        } finally {
            sm.close(resultSet);
            sm.close(conn);
        }

        try {
            Thread.sleep(rate);
        } catch (InterruptedException e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:gsn.wrappers.TetraedreFluoWrapper.java

public void run() {
    DataEnumerator data;/*  w  w w.  j av  a2  s.co m*/

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
    }

    Connection conn = null;
    ResultSet resultSet = null;

    while (isActive()) {
        try {
            conn = sm.getConnection();
            StringBuilder query = new StringBuilder("select * from ").append(table_name)
                    .append(" where physical_input=").append(physical_input).append(" AND timestamp*1000 > "
                            + latest_timed + "  order by timestamp limit 0," + buffer_size);

            resultSet = sm.executeQueryWithResultSet(query, conn);

            //logger.debug(query);

            while (resultSet.next()) {
                Serializable[] output = new Serializable[this.getOutputFormat().length];

                //long pk = resultSet.getLong(1);
                long timed = resultSet.getLong(3) * 1000;

                //logger.warn("pk => "+ pk);
                //logger.warn("timed => "+ timed);

                for (int i = 0; i < dataFieldsLength; i++) {

                    switch (dataFieldTypes[i]) {
                    case DataTypes.VARCHAR:
                    case DataTypes.CHAR:
                        output[i] = resultSet.getString(i + 1);
                        break;
                    case DataTypes.INTEGER:
                        output[i] = resultSet.getInt(i + 1);
                        break;
                    case DataTypes.TINYINT:
                        output[i] = resultSet.getByte(i + 1);
                        break;
                    case DataTypes.SMALLINT:
                        output[i] = resultSet.getShort(i + 1);
                        break;
                    case DataTypes.DOUBLE:
                        output[i] = resultSet.getDouble(i + 1);
                        break;
                    case DataTypes.FLOAT:
                        output[i] = resultSet.getFloat(i + 1);
                        break;
                    case DataTypes.BIGINT:
                        output[i] = resultSet.getLong(i + 1);
                        break;
                    case DataTypes.BINARY:
                        output[i] = resultSet.getBytes(i + 1);
                        break;
                    }
                    //logger.warn(i+" (type: "+dataFieldTypes[i]+" ) => "+output[i]);
                }

                StreamElement se = new StreamElement(dataFieldNames, dataFieldTypes, output, timed);
                latest_timed = se.getTimeStamp();

                //logger.warn(" Latest => " + latest_timed);

                this.postStreamElement(se);

                updateCheckPointFile(latest_timed);

                //logger.warn(se);
            }

        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        } catch (SQLException e) {
            logger.error(e.getMessage(), e);
        } finally {
            sm.close(resultSet);
            sm.close(conn);
        }

        try {
            Thread.sleep(rate);
        } catch (InterruptedException e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:com.l2jfree.gameserver.model.items.L2ItemInstance.java

public void restoreAttributes() {
    Connection con = null;/*from   w w w.ja v  a2  s  .  com*/
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "SELECT augAttributes,augSkillId,augSkillLevel,elemType,elemValue FROM item_attributes WHERE itemId=?");
        statement.setInt(1, getObjectId());
        ResultSet rs = statement.executeQuery();
        rs = statement.executeQuery();
        if (rs.next()) {
            int aug_attributes = rs.getInt(1);
            int aug_skillId = rs.getInt(2);
            int aug_skillLevel = rs.getInt(3);
            byte elem_type = rs.getByte(4);
            int elem_value = rs.getInt(5);
            if (elem_type != -1 && elem_value != -1)
                _elementals = new Elementals(elem_type, elem_value);
            if (aug_attributes != -1 && aug_skillId != -1 && aug_skillLevel != -1)
                _augmentation = new L2Augmentation(aug_attributes, aug_skillId, aug_skillLevel);
        }
        rs.close();
        statement.close();
    } catch (Exception e) {
        _log.fatal("Could not restore augmentation and elemental data for item " + getObjectId() + " from DB: "
                + e.getMessage(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:org.springframework.jdbc.core.AbstractBeanPropertyRowMapper.java

protected Object doMapRow(ResultSet rs, int rowNumber) throws SQLException {
    if (getMappedClass() == null)
        throw new InvalidDataAccessApiUsageException("Target class was not specified - it is mandatory");
    Object result;//from  w  w  w  .j av  a  2  s  .  c  o  m
    try {
        result = this.defaultConstruct.newInstance((Object[]) null);
    } catch (IllegalAccessException e) {
        throw new DataAccessResourceFailureException("Failed to load class " + this.mappedClass.getName(), e);
    } catch (InvocationTargetException e) {
        throw new DataAccessResourceFailureException("Failed to load class " + this.mappedClass.getName(), e);
    } catch (InstantiationException e) {
        throw new DataAccessResourceFailureException("Failed to load class " + this.mappedClass.getName(), e);
    }
    ResultSetMetaData rsmd = rs.getMetaData();
    int columns = rsmd.getColumnCount();
    for (int i = 1; i <= columns; i++) {
        String column = JdbcUtils.lookupColumnName(rsmd, i).toLowerCase();
        PersistentField fieldMeta = (PersistentField) this.mappedFields.get(column);
        if (fieldMeta != null) {
            BeanWrapper bw = new BeanWrapperImpl(mappedClass);
            bw.setWrappedInstance(result);
            fieldMeta.setSqlType(rsmd.getColumnType(i));
            Object value = null;
            Class fieldType = fieldMeta.getJavaType();
            if (fieldType.equals(String.class)) {
                value = rs.getString(column);
            } else if (fieldType.equals(byte.class) || fieldType.equals(Byte.class)) {
                value = new Byte(rs.getByte(column));
            } else if (fieldType.equals(short.class) || fieldType.equals(Short.class)) {
                value = new Short(rs.getShort(column));
            } else if (fieldType.equals(int.class) || fieldType.equals(Integer.class)) {
                value = new Integer(rs.getInt(column));
            } else if (fieldType.equals(long.class) || fieldType.equals(Long.class)) {
                value = new Long(rs.getLong(column));
            } else if (fieldType.equals(float.class) || fieldType.equals(Float.class)) {
                value = new Float(rs.getFloat(column));
            } else if (fieldType.equals(double.class) || fieldType.equals(Double.class)) {
                value = new Double(rs.getDouble(column));
            } else if (fieldType.equals(BigDecimal.class)) {
                value = rs.getBigDecimal(column);
            } else if (fieldType.equals(boolean.class) || fieldType.equals(Boolean.class)) {
                value = (rs.getBoolean(column)) ? Boolean.TRUE : Boolean.FALSE;
            } else if (fieldType.equals(java.util.Date.class) || fieldType.equals(java.sql.Timestamp.class)
                    || fieldType.equals(java.sql.Time.class) || fieldType.equals(Number.class)) {
                value = JdbcUtils.getResultSetValue(rs, rs.findColumn(column));
            }
            if (value != null) {
                if (bw.isWritableProperty(fieldMeta.getFieldName())) {
                    try {
                        if (logger.isDebugEnabled() && rowNumber == 0) {
                            logger.debug("Mapping column named \"" + column + "\""
                                    + " containing values of SQL type " + fieldMeta.getSqlType()
                                    + " to property \"" + fieldMeta.getFieldName() + "\"" + " of type "
                                    + fieldMeta.getJavaType());
                        }
                        bw.setPropertyValue(fieldMeta.getFieldName(), value);
                    } catch (NotWritablePropertyException ex) {
                        throw new DataRetrievalFailureException(
                                "Unable to map column " + column + " to property " + fieldMeta.getFieldName(),
                                ex);
                    }
                } else {
                    if (rowNumber == 0) {
                        logger.warn("Unable to access the setter for " + fieldMeta.getFieldName()
                                + ".  Check that " + "set" + StringUtils.capitalize(fieldMeta.getFieldName())
                                + " is declared and has public access.");
                    }
                }
            }
        }
    }
    return result;
}

From source file:org.sleuthkit.autopsy.timeline.db.EventDB.java

private SingleEvent constructTimeLineEvent(ResultSet rs) throws SQLException {
    return new SingleEvent(rs.getLong("event_id"), //NON-NLS
            rs.getLong("datasource_id"), //NON-NLS
            rs.getLong("file_id"), //NON-NLS
            rs.getLong("artifact_id"), //NON-NLS
            rs.getLong("time"), RootEventType.allTypes.get(rs.getInt("sub_type")), //NON-NLS
            rs.getString("full_description"), //NON-NLS
            rs.getString("med_description"), //NON-NLS
            rs.getString("short_description"), //NON-NLS
            TskData.FileKnown.valueOf(rs.getByte("known_state")), //NON-NLS
            rs.getInt("hash_hit") != 0, //NON-NLS
            rs.getInt("tagged") != 0); //NON-NLS
}

From source file:org.latticesoft.util.resource.dao.Param.java

private Object readValue(ResultSet rs) throws SQLException {
    Object retVal = null;/*w w  w. ja  v  a  2 s . c  o m*/
    switch (this.sqlType) {
    case Types.VARCHAR:
    case Types.CHAR:
        String s = null;
        if (this.getSqlIndex() == 0) {
            s = rs.getString(this.getSqlName());
        } else {
            s = rs.getString(this.getSqlIndex());
        }
        retVal = s;
        break;
    case Types.BOOLEAN:
        boolean b = false;
        if (this.getSqlIndex() == 0) {
            b = rs.getBoolean(this.getSqlName());
        } else {
            b = rs.getBoolean(this.getSqlIndex());
        }
        retVal = new Boolean(b);
        break;
    case Types.INTEGER:
        int i = 0;
        if (this.getSqlIndex() == 0) {
            i = rs.getInt(this.getSqlName());
        } else {
            i = rs.getInt(this.getSqlIndex());
        }
        retVal = new Integer(i);
        break;
    case Types.SMALLINT:
        short ss = 0;
        if (this.getSqlIndex() == 0) {
            ss = rs.getShort(this.getSqlName());
        } else {
            ss = rs.getShort(this.getSqlIndex());
        }
        retVal = new Short(ss);
        break;
    case Types.TINYINT:
        byte bb = 0;
        if (this.getSqlIndex() == 0) {
            bb = rs.getByte(this.getSqlName());
        } else {
            bb = rs.getByte(this.getSqlIndex());
        }
        retVal = new Byte(bb);
        break;
    case Types.BIGINT:
        long l = 0;
        if (this.getSqlIndex() == 0) {
            l = rs.getLong(this.getSqlName());
        } else {
            l = rs.getLong(this.getSqlIndex());
        }
        retVal = new Long(l);
        break;
    case Types.DOUBLE:
        double dd = 0;
        if (this.getSqlIndex() == 0) {
            dd = rs.getDouble(this.getSqlName());
        } else {
            dd = rs.getDouble(this.getSqlIndex());
        }
        retVal = new Double(dd);
        break;
    case Types.FLOAT:
        float f = 0;
        if (this.getSqlIndex() == 0) {
            f = rs.getFloat(this.getSqlName());
        } else {
            f = rs.getFloat(this.getSqlIndex());
        }
        retVal = new Float(f);
        break;
    case Types.NUMERIC:
        BigDecimal bd = null;
        if (this.getSqlIndex() == 0) {
            bd = rs.getBigDecimal(this.getSqlName());
        } else {
            bd = rs.getBigDecimal(this.getSqlIndex());
        }
        retVal = bd;
        break;
    case Types.TIMESTAMP:
        Timestamp ts = null;
        if (this.getSqlIndex() == 0) {
            ts = rs.getTimestamp(this.getSqlName());
        } else {
            ts = rs.getTimestamp(this.getSqlIndex());
        }
        retVal = ts;
        break;
    default:
        if (this.getSqlIndex() == 0) {
            retVal = rs.getObject(this.getSqlName());
        } else {
            retVal = rs.getObject(this.getSqlIndex());
        }
        break;
    }
    if (log.isDebugEnabled()) {
        log.debug(this.getAttribute() + "=" + retVal);
    }
    return retVal;
}

From source file:net.pms.dlna.DLNAMediaDatabase.java

public ArrayList<DLNAMediaInfo> getData(String name, long modified) {
    ArrayList<DLNAMediaInfo> list = new ArrayList<DLNAMediaInfo>();
    Connection conn = null;//from ww w.  j  a  v  a 2s  .  c om
    ResultSet rs = null;
    PreparedStatement stmt = null;
    try {
        conn = getConnection();
        stmt = conn.prepareStatement("SELECT * FROM FILES WHERE FILENAME = ? AND MODIFIED = ?");
        stmt.setString(1, name);
        stmt.setTimestamp(2, new Timestamp(modified));
        rs = stmt.executeQuery();
        while (rs.next()) {
            DLNAMediaInfo media = new DLNAMediaInfo();
            int id = rs.getInt("ID");
            media.setDuration(toDouble(rs, "DURATION"));
            media.setBitrate(rs.getInt("BITRATE"));
            media.setWidth(rs.getInt("WIDTH"));
            media.setHeight(rs.getInt("HEIGHT"));
            media.setSize(rs.getLong("SIZE"));
            media.setCodecV(rs.getString("CODECV"));
            media.setFrameRate(rs.getString("FRAMERATE"));
            media.setAspect(rs.getString("ASPECT"));
            media.setAspectRatioContainer(rs.getString("ASPECTRATIOCONTAINER"));
            media.setAspectRatioVideoTrack(rs.getString("ASPECTRATIOVIDEOTRACK"));
            media.setReferenceFrameCount(rs.getByte("REFRAMES"));
            media.setAvcLevel(rs.getString("AVCLEVEL"));
            media.setBitsPerPixel(rs.getInt("BITSPERPIXEL"));
            media.setThumb(rs.getBytes("THUMB"));
            media.setContainer(rs.getString("CONTAINER"));
            media.setModel(rs.getString("MODEL"));
            if (media.getModel() != null && !FormatConfiguration.JPG.equals(media.getContainer())) {
                media.setExtrasAsString(media.getModel());
            }
            media.setExposure(rs.getInt("EXPOSURE"));
            media.setOrientation(rs.getInt("ORIENTATION"));
            media.setIso(rs.getInt("ISO"));
            media.setMuxingMode(rs.getString("MUXINGMODE"));
            media.setFrameRateMode(rs.getString("FRAMERATEMODE"));
            media.setMediaparsed(true);
            PreparedStatement audios = conn.prepareStatement("SELECT * FROM AUDIOTRACKS WHERE FILEID = ?");
            audios.setInt(1, id);
            ResultSet subrs = audios.executeQuery();
            while (subrs.next()) {
                DLNAMediaAudio audio = new DLNAMediaAudio();
                audio.setId(subrs.getInt("ID"));
                audio.setLang(subrs.getString("LANG"));
                audio.setFlavor(subrs.getString("FLAVOR"));
                audio.getAudioProperties().setNumberOfChannels(subrs.getInt("NRAUDIOCHANNELS"));
                audio.setSampleFrequency(subrs.getString("SAMPLEFREQ"));
                audio.setCodecA(subrs.getString("CODECA"));
                audio.setBitsperSample(subrs.getInt("BITSPERSAMPLE"));
                audio.setAlbum(subrs.getString("ALBUM"));
                audio.setArtist(subrs.getString("ARTIST"));
                audio.setSongname(subrs.getString("SONGNAME"));
                audio.setGenre(subrs.getString("GENRE"));
                audio.setYear(subrs.getInt("YEAR"));
                audio.setTrack(subrs.getInt("TRACK"));
                audio.getAudioProperties().setAudioDelay(subrs.getInt("DELAY"));
                audio.setMuxingModeAudio(subrs.getString("MUXINGMODE"));
                audio.setBitRate(subrs.getInt("BITRATE"));
                media.getAudioTracksList().add(audio);
            }
            subrs.close();
            audios.close();

            PreparedStatement subs = conn.prepareStatement("SELECT * FROM SUBTRACKS WHERE FILEID = ?");
            subs.setInt(1, id);
            subrs = subs.executeQuery();
            while (subrs.next()) {
                DLNAMediaSubtitle sub = new DLNAMediaSubtitle();
                sub.setId(subrs.getInt("ID"));
                sub.setLang(subrs.getString("LANG"));
                sub.setFlavor(subrs.getString("FLAVOR"));
                sub.setType(SubtitleType.valueOfStableIndex(subrs.getInt("TYPE")));
                media.getSubtitleTracksList().add(sub);
            }
            subrs.close();
            subs.close();

            list.add(media);
        }
    } catch (SQLException se) {
        logger.error(null, se);
        return null;
    } finally {
        close(rs);
        close(stmt);
        close(conn);
    }
    return list;
}

From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java

public void testDataTypes() throws Exception {
    Statement stmt = con.createStatement();

    ResultSet res = stmt.executeQuery("select * from " + dataTypeTableName + " order by c1");
    ResultSetMetaData meta = res.getMetaData();

    // row 1//  w ww  .j a  v  a 2s.c  o  m
    assertTrue(res.next());
    // skip the last (partitioning) column since it is always non-null
    for (int i = 1; i < meta.getColumnCount(); i++) {
        assertNull(res.getObject(i));
    }

    // row 2
    assertTrue(res.next());
    assertEquals(-1, res.getInt(1));
    assertEquals(false, res.getBoolean(2));
    assertEquals(-1.1d, res.getDouble(3));
    assertEquals("", res.getString(4));
    assertEquals("[]", res.getString(5));
    assertEquals("{}", res.getString(6));
    assertEquals("{}", res.getString(7));
    assertEquals("[null, null, null]", res.getString(8));
    assertEquals(-1, res.getByte(9));
    assertEquals(-1, res.getShort(10));
    assertEquals(-1.0f, res.getFloat(11));
    assertEquals(-1, res.getLong(12));
    assertEquals("[]", res.getString(13));
    assertEquals("{}", res.getString(14));
    assertEquals("[null, null]", res.getString(15));
    assertEquals("[]", res.getString(16));
    assertEquals(null, res.getString(17));
    assertEquals(null, res.getTimestamp(17));
    assertEquals(null, res.getBigDecimal(18));
    assertEquals(null, res.getString(20));
    assertEquals(null, res.getDate(20));

    // row 3
    assertTrue(res.next());
    assertEquals(1, res.getInt(1));
    assertEquals(true, res.getBoolean(2));
    assertEquals(1.1d, res.getDouble(3));
    assertEquals("1", res.getString(4));
    assertEquals("[1, 2]", res.getString(5));
    assertEquals("{1=x, 2=y}", res.getString(6));
    assertEquals("{k=v}", res.getString(7));
    assertEquals("[a, 9, 2.2]", res.getString(8));
    assertEquals(1, res.getByte(9));
    assertEquals(1, res.getShort(10));
    assertEquals(1.0f, res.getFloat(11));
    assertEquals(1, res.getLong(12));
    assertEquals("[[a, b], [c, d]]", res.getString(13));
    assertEquals("{1={11=12, 13=14}, 2={21=22}}", res.getString(14));
    assertEquals("[1, [2, x]]", res.getString(15));
    assertEquals("[[{}, 1], [{c=d, a=b}, 2]]", res.getString(16));
    assertEquals("2012-04-22 09:00:00.123456789", res.getString(17));
    assertEquals("2012-04-22 09:00:00.123456789", res.getTimestamp(17).toString());
    assertEquals("123456789.0123456", res.getBigDecimal(18).toString());
    assertEquals("2013-01-01", res.getString(20));
    assertEquals("2013-01-01", res.getDate(20).toString());

    // test getBoolean rules on non-boolean columns
    assertEquals(true, res.getBoolean(1));
    assertEquals(true, res.getBoolean(4));

    // no more rows
    assertFalse(res.next());
}

From source file:ResultSetIterator.java

/**
 * Convert a <code>ResultSet</code> column into an object.  Simple 
 * implementations could just call <code>rs.getObject(index)</code> while
 * more complex implementations could perform type manipulation to match 
 * the column's type to the bean property type.
 * //from   ww  w  .  j a v  a 2s  .c om
 * <p>
 * This implementation calls the appropriate <code>ResultSet</code> getter 
 * method for the given property type to perform the type conversion.  If 
 * the property type doesn't match one of the supported 
 * <code>ResultSet</code> types, <code>getObject</code> is called.
 * </p>
 * 
 * @param rs The <code>ResultSet</code> currently being processed.  It is
 * positioned on a valid row before being passed into this method.
 * 
 * @param index The current column index being processed.
 * 
 * @param propType The bean property type that this column needs to be
 * converted into.
 * 
 * @throws SQLException if a database access error occurs
 * 
 * @return The object from the <code>ResultSet</code> at the given column
 * index after optional type processing or <code>null</code> if the column
 * value was SQL NULL.
 */
protected Object processColumn(ResultSet rs, int index, Class propType) throws SQLException {

    if (!propType.isPrimitive() && rs.getObject(index) == null) {
        return null;
    }

    if (propType.equals(String.class)) {
        return rs.getString(index);

    } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) {
        return new Integer(rs.getInt(index));

    } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) {
        return new Boolean(rs.getBoolean(index));

    } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) {
        return new Long(rs.getLong(index));

    } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) {
        return new Double(rs.getDouble(index));

    } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) {
        return new Float(rs.getFloat(index));

    } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) {
        return new Short(rs.getShort(index));

    } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) {
        return new Byte(rs.getByte(index));

    } else if (propType.equals(Timestamp.class)) {
        return rs.getTimestamp(index);

    } else {
        return rs.getObject(index);
    }

}