Example usage for java.sql ResultSet getTimestamp

List of usage examples for java.sql ResultSet getTimestamp

Introduction

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

Prototype

java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

From source file:net.agmodel.metbroker.driver.impl.JmaGsmGl.java

/**
 * get database connection and execute SQL command.
 * And put the result to Sequence Object
 * @param seqMap Sequence Map/*from  w ww .ja  v  a  2  s.c  o  m*/
 * @param stationId station id
 * @param query SQL statement
 * @param start start date
 * @param end end date
 * @param hourly if true, use SIX_HOURS, else ONE_DAY
 * @throws DriverException something fail.
 */
private void queryTable(StationDataSetProxy seqMap, String stationId, String query, Date start, Date end,
        boolean hourly) throws DriverException {
    Connection con = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    java.sql.Timestamp startDate = new java.sql.Timestamp(start.getTime());

    java.sql.Timestamp endDate = new java.sql.Timestamp(end.getTime());
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

    try {
        con = dataSource.getConnection();

        logger.debug("Connection: " + con.toString());

        /*         stmt = con.prepareStatement(query);
                 stmt.setInt(1, new Integer(stationId).intValue());
                 stmt.setTimestamp(2, startDate, cal);
                 stmt.setTimestamp(3, endDate, cal);
                 stmt.setInt(4, new Integer(stationId).intValue());
                 stmt.setTimestamp(5, startDate, cal);
                 stmt.setTimestamp(6, endDate, cal);
        */
        stmt = con.prepareStatement(query);
        stmt.setInt(1, new Integer(stationId).intValue());
        stmt.setTimestamp(2, startDate);
        stmt.setTimestamp(3, endDate);
        stmt.setInt(4, new Integer(stationId).intValue());
        stmt.setTimestamp(5, startDate);
        stmt.setTimestamp(6, endDate);

        rs = stmt.executeQuery();

        logger.debug("ResultSet: " + rs.toString());

        AirTemperature tempSequence = null;
        if (seqMap.containsKey(MetElement.AIRTEMPERATURE)) {
            tempSequence = (AirTemperature) seqMap.getSequence(MetElement.AIRTEMPERATURE);
        }
        Rain rainSequence = null;
        if (seqMap.containsKey(MetElement.RAIN)) {
            rainSequence = (Rain) seqMap.getSequence(MetElement.RAIN);
        }
        Humidity humiditySequence = null;
        if (seqMap.containsKey(MetElement.HUMIDITY)) {
            humiditySequence = (Humidity) seqMap.getSequence(MetElement.HUMIDITY);
        }
        Wind windSequence = null;
        if (seqMap.containsKey(MetElement.WIND)) {
            windSequence = (Wind) seqMap.getSequence(MetElement.WIND);
        }

        while (rs.next()) {
            java.util.Date recordTime = null;
            MutableInterval dataInterval = new MutableInterval();
            recordTime = rs.getTimestamp("end_date");

            if (hourly) {
                dataInterval.set(Duration.SIX_HOURS, recordTime);
            } else {
                dataInterval.set(Duration.ONE_DAY, recordTime);
            }
            if (seqMap.containsKey(MetElement.AIRTEMPERATURE)) {
                float dummy = (float) (rs.getFloat("temperature") - 273.15);
                if (!rs.wasNull()) {
                    ((AirTempMaxMinMeanImpl) tempSequence).putMeanOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.RAIN)) {
                float dummy = rs.getFloat("total_preciptasion");
                if (!rs.wasNull()) {
                    ((RainImpl) rainSequence).putRainfallOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.HUMIDITY)) {
                float dummy = rs.getFloat("relative_humidity");
                if (!rs.wasNull()) {
                    ((RHImpl) humiditySequence).putRHOverInterval(dataInterval, dummy);
                }
            }
            if (seqMap.containsKey(MetElement.WIND)) {
                float u = rs.getFloat("u_wind");
                if (!rs.wasNull()) {
                    float v = rs.getFloat("v_wind");
                    if (!rs.wasNull()) {
                        ((Wind2DImpl) windSequence).putSpeedOverInterval(dataInterval, v, u);
                    }
                }
            }
        }
    } catch (SQLException s) {
        s.printStackTrace();
    } finally {
        try {
            rs.close();
        } catch (Exception s) {
        }
        try {
            stmt.close();
        } catch (Exception s) {
        }
        try {
            con.close();
        } catch (Exception e) {
        }

    }

}

From source file:chh.utils.db.source.common.JdbcClient.java

public List<List<Column>> select(String sqlQuery, List<Column> queryParams) {
    Connection connection = null;
    try {/*from  www .  j  a  v  a  2s.  c  o m*/
        connection = connectionProvider.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery);
        if (queryTimeoutSecs > 0) {
            preparedStatement.setQueryTimeout(queryTimeoutSecs);
        }
        setPreparedStatementParams(preparedStatement, queryParams);
        ResultSet resultSet = preparedStatement.executeQuery();
        List<List<Column>> rows = Lists.newArrayList();
        while (resultSet.next()) {
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columnCount = metaData.getColumnCount();
            List<Column> row = Lists.newArrayList();
            for (int i = 1; i <= columnCount; i++) {
                String columnLabel = metaData.getColumnLabel(i);
                int columnType = metaData.getColumnType(i);
                Class columnJavaType = Util.getJavaType(columnType);
                if (columnJavaType.equals(String.class)) {
                    row.add(new Column<String>(columnLabel, resultSet.getString(columnLabel), columnType));
                } else if (columnJavaType.equals(Integer.class)) {
                    row.add(new Column<Integer>(columnLabel, resultSet.getInt(columnLabel), columnType));
                } else if (columnJavaType.equals(Double.class)) {
                    row.add(new Column<Double>(columnLabel, resultSet.getDouble(columnLabel), columnType));
                } else if (columnJavaType.equals(Float.class)) {
                    row.add(new Column<Float>(columnLabel, resultSet.getFloat(columnLabel), columnType));
                } else if (columnJavaType.equals(Short.class)) {
                    row.add(new Column<Short>(columnLabel, resultSet.getShort(columnLabel), columnType));
                } else if (columnJavaType.equals(Boolean.class)) {
                    row.add(new Column<Boolean>(columnLabel, resultSet.getBoolean(columnLabel), columnType));
                } else if (columnJavaType.equals(byte[].class)) {
                    row.add(new Column<byte[]>(columnLabel, resultSet.getBytes(columnLabel), columnType));
                } else if (columnJavaType.equals(Long.class)) {
                    row.add(new Column<Long>(columnLabel, resultSet.getLong(columnLabel), columnType));
                } else if (columnJavaType.equals(Date.class)) {
                    row.add(new Column<Date>(columnLabel, resultSet.getDate(columnLabel), columnType));
                } else if (columnJavaType.equals(Time.class)) {
                    row.add(new Column<Time>(columnLabel, resultSet.getTime(columnLabel), columnType));
                } else if (columnJavaType.equals(Timestamp.class)) {
                    row.add(new Column<Timestamp>(columnLabel, resultSet.getTimestamp(columnLabel),
                            columnType));
                } else {
                    throw new RuntimeException(
                            "type =  " + columnType + " for column " + columnLabel + " not supported.");
                }
            }
            rows.add(row);
        }
        return rows;
    } catch (SQLException e) {
        throw new RuntimeException("Failed to execute select query " + sqlQuery, e);
    } finally {
        closeConnection(connection);
    }
}

From source file:fr.aliacom.obm.common.contact.ContactDaoJdbcImpl.java

private void loadBirthday(Connection con, Map<EntityId, Contact> entityContact) {
    PreparedStatement ps = null;// w ww.j  a  v  a2  s  .  co m
    ResultSet rs = null;
    Set<EventObmId> bdayIds = new HashSet<EventObmId>();
    HashMap<EventObmId, Contact> eventIdMap = new HashMap<EventObmId, Contact>();
    for (Contact c : entityContact.values()) {
        if (c.getBirthdayId() != null) {
            bdayIds.add(c.getBirthdayId());
            eventIdMap.put(c.getBirthdayId(), c);
        }
    }
    if (bdayIds.isEmpty()) {
        return;
    }

    IntegerIndexedSQLCollectionHelper eventIds = new IntegerIndexedSQLCollectionHelper(bdayIds);
    String q = "select event_id, event_date from Event where event_id IN (" + eventIds.asPlaceHolders() + ")";
    try {
        ps = con.prepareStatement(q);
        eventIds.insertValues(ps, 1);
        rs = ps.executeQuery();
        while (rs.next()) {
            EventObmId evId = new EventObmId(rs.getInt(1));
            Contact c = eventIdMap.get(evId);
            c.setBirthday(rs.getTimestamp(2));
        }
    } catch (SQLException se) {
        logger.error(se.getMessage(), se);
    } finally {
        obmHelper.cleanup(null, ps, rs);
    }
}

From source file:fr.aliacom.obm.common.contact.ContactDaoJdbcImpl.java

private void loadAnniversary(Connection con, Map<EntityId, Contact> entityContact) {
    PreparedStatement ps = null;//from  ww  w .j a v a2s.  c o m
    ResultSet rs = null;
    Set<EventObmId> bdayIds = new HashSet<EventObmId>();
    HashMap<EventObmId, Contact> eventIdMap = new HashMap<EventObmId, Contact>();
    for (Contact c : entityContact.values()) {
        if (c.getAnniversaryId() != null) {
            bdayIds.add(c.getAnniversaryId());
            eventIdMap.put(c.getAnniversaryId(), c);
        }
    }
    if (bdayIds.isEmpty()) {
        return;
    }

    IntegerIndexedSQLCollectionHelper eventIds = new IntegerIndexedSQLCollectionHelper(bdayIds);
    String q = "select event_id, event_date from Event where event_id IN (" + eventIds.asPlaceHolders() + ")";
    try {
        ps = con.prepareStatement(q);
        eventIds.insertValues(ps, 1);
        rs = ps.executeQuery();
        while (rs.next()) {
            EventObmId evId = new EventObmId(rs.getInt(1));
            Contact c = eventIdMap.get(evId);
            c.setAnniversary(rs.getTimestamp(2));
        }
    } catch (SQLException se) {
        logger.error(se.getMessage(), se);
    } finally {
        obmHelper.cleanup(null, ps, rs);
    }
}

From source file:com.sfs.whichdoctor.dao.CreditDAOImpl.java

/**
 * Load credit./*from   w  w w  .  j a  va  2s  . c om*/
 *
 * @param rs the rs
 * @param loadDetails the load details
 *
 * @return the credit bean
 *
 * @throws SQLException the SQL exception
 */
private CreditBean loadCredit(final ResultSet rs, final BuilderBean loadDetails) throws SQLException {

    CreditBean credit = new CreditBean();

    // Create resource bean and fill with dataset info.
    credit.setId(rs.getInt("CreditId"));
    credit.setGUID(rs.getInt("GUID"));

    credit.setAbbreviation(rs.getString("Abbreviation"));
    credit.setTypeName(rs.getString("Type"));
    credit.setClassName(rs.getString("CreditType"));

    credit.setNumber(rs.getString("CreditNo"));

    credit.setDescription(rs.getString("Description"));

    credit.setPersonId(rs.getInt("PersonId"));
    if (credit.getPersonId() > 0) {
        credit.setPerson(loadPerson(rs, credit.getPersonId(), loadDetails));
    }

    credit.setOrganisationId(rs.getInt("OrganisationId"));
    if (credit.getOrganisationId() > 0) {
        credit.setOrganisation(loadOrganisation(rs, credit.getOrganisationId(), loadDetails));
    }

    credit.setValue(rs.getDouble("Value"));
    credit.setNetValue(rs.getDouble("NetValue"));
    try {
        credit.setIssued(rs.getDate("Issued"));
    } catch (SQLException e) {
        credit.setIssued(null);
    }
    credit.setCancelled(rs.getBoolean("Cancelled"));
    credit.setGSTRate(rs.getDouble("GSTRate"));

    if (loadDetails.getBoolean("DEBITS_FULL")) {
        int debitGUID = rs.getInt("InvoiceId");
        if (debitGUID > 0) {
            DebitBean debit = new DebitBean();
            try {
                debit = this.getDebitDAO().loadGUID(debitGUID);
            } catch (Exception e) {
                dataLogger.error("Error loading debit for credit: " + e.getMessage());
            }
            if (debit.getId() > 0) {
                credit.setDebit(debit);
            }
        }
    }
    credit.setSecurity(rs.getString("Security"));

    credit.setActive(rs.getBoolean("Active"));
    if (loadDetails.getBoolean("HISTORY")) {
        try {
            credit.setCreatedDate(rs.getTimestamp("CreatedDate"));
        } catch (SQLException sqe) {
            dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage());
        }
        credit.setCreatedBy(rs.getString("CreatedBy"));
        try {
            credit.setModifiedDate(rs.getTimestamp("ModifiedDate"));
        } catch (SQLException sqe) {
            dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage());
        }
        credit.setModifiedBy(rs.getString("ModifiedBy"));
        try {
            credit.setExportedDate(rs.getTimestamp("ExportedDate"));
        } catch (SQLException sqe) {
            dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage());
        }
        credit.setExportedBy(rs.getString("ExportedBy"));
    }

    if (loadDetails.getBoolean("TAGS")) {
        try {
            credit.setTags(this.getTagDAO().load(credit.getGUID(), loadDetails.getString("USERDN"), true));
        } catch (Exception e) {
            dataLogger.error("Error loading tags for credit: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("MEMO")) {
        try {
            credit.setMemo(this.getMemoDAO().load(credit.getGUID(), loadDetails.getBoolean("MEMO_FULL")));
        } catch (Exception e) {
            dataLogger.error("Error loading memos for credit: " + e.getMessage());
        }
    }

    if (loadDetails.getBoolean("GROUPS")) {
        credit.setGroups(loadGroups(credit.getGUID()));
    }

    if (loadDetails.getBoolean("CREATED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("CreatedBy"));
        user.setPreferredName(rs.getString("CreatedFirstName"));
        user.setLastName(rs.getString("CreatedLastName"));
        credit.setCreatedUser(user);
    }
    if (loadDetails.getBoolean("MODIFIED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("ModifiedBy"));
        user.setPreferredName(rs.getString("ModifiedFirstName"));
        user.setLastName(rs.getString("ModifiedLastName"));
        credit.setModifiedUser(user);
    }
    if (loadDetails.getBoolean("EXPORTED")) {
        UserBean user = new UserBean();
        user.setDN(rs.getString("ExportedBy"));
        user.setPreferredName(rs.getString("ExportedFirstName"));
        user.setLastName(rs.getString("ExportedLastName"));
        credit.setExportedUser(user);
    }
    return credit;
}

From source file:edu.ku.brc.specify.utilapps.RegProcessor.java

/**
 * @param inFile//from  w  w w. j  ava2  s  .co  m
 */
public void processSQL() {
    String sql = "SELECT r.RegisterID, r.RegNumber, ri.Name, ri.Value, ri.CountAmt, r.TimestampCreated, r.IP"
            + " FROM register r INNER JOIN registeritem ri ON r.RegisterID = ri.RegisterID WHERE r.TimestampCreated > '2009-04-12' ORDER BY r.RegNumber";
    System.err.println(sql);
    //Connection connection = DBConnection.getInstance().getConnection();
    try {
        stmt = DBConnection.getInstance().getConnection().createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        int prevId = Integer.MAX_VALUE;
        RegProcEntry currEntry = null;
        while (rs.next()) {
            int id = rs.getInt(1);
            if (id != prevId) {
                if (currEntry != null) {
                    String regType = currEntry.get("reg_type");
                    if (regType != null) {
                        Hashtable<String, RegProcEntry> entryHash = typeHash.get(regType);
                        if (entryHash == null) {
                            entryHash = new Hashtable<String, RegProcEntry>();
                            typeHash.put(regType, entryHash);
                        }
                        currEntry.put("reg_number", currEntry.getId());
                        currEntry.setType(currEntry.get("reg_type"));

                        if (entryHash.get(currEntry.getId()) == null) {
                            entryHash.put(currEntry.getId(), currEntry);
                        } else {
                            System.err.println("Already there: " + currEntry.getId());
                        }
                    } else {
                        System.err.println("1Skipping: " + rs.getString(2));
                    }
                }

                String regNumber = rs.getString(2);
                String ip = rs.getString(7);
                currEntry = regNumHash.get(regNumber);
                if (currEntry == null) {
                    if (ip != null) {
                        currEntry = new RegProcEntry();
                        regNumHash.put(regNumber, currEntry);
                        currEntry.setId(regNumber);
                        currEntry.setTimestampCreated(rs.getTimestamp(6));
                        currEntry.put("ip", ip);

                    } else {
                        System.err.println("IP is null for " + regNumber);
                        ip = "N/A";
                    }

                } else {
                    System.err.println("Already " + regNumber);
                }

                prevId = id;

            } else if (prevId == Integer.MAX_VALUE) {
                prevId = id;
            }

            String value = rs.getString(4);
            if (value == null) {
                value = rs.getString(5);
            }

            String propName = rs.getString(3);
            if (currEntry != null && value != null && propName != null) {
                currEntry.put(propName, value);
            }
        }
        rs.close();

        Hashtable<String, RegProcEntry> checkHash = new Hashtable<String, RegProcEntry>();
        Hashtable<String, RegProcEntry> instHash = typeHash.get("Institution");

        for (RegProcEntry entry : new Vector<RegProcEntry>(regNumHash.values())) {
            entry.setName(null);
            String ip = entry.get("ip");
            if (ip == null || ip.startsWith("129.") || ip.startsWith("24.")) {
                System.out.println("Removing ip: " + ip);
                instHash.remove(entry.getId());
                regNumHash.remove(entry.getId());

            } else {
                RegProcEntry e = checkHash.get(ip);
                if (e == null) {
                    checkHash.put(ip, entry);
                } else {
                    instHash.remove(e.getId());
                    regNumHash.remove(e.getId());
                    checkHash.put(ip, entry);
                    System.out.println("Compressing ip: " + ip);
                }
            }
        }

        buildTree();

    } catch (SQLException ex) {
        ex.printStackTrace();

    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:fr.aliacom.obm.common.calendar.CalendarDaoJdbcImpl.java

private Set<Date> getAllDateEventException(Connection con, EventObmId id) {
    Set<Date> ret = new HashSet<Date>();

    String q = "SELECT eventexception_date FROM EventException "
            + " INNER JOIN Event ON eventexception_parent_id = event_id" + " WHERE eventexception_parent_id=?";
    PreparedStatement ps = null;/* w  ww  . j a  va2  s .  c om*/
    ResultSet rs = null;
    try {
        ps = con.prepareStatement(q);
        ps.setInt(1, id.getObmId());
        rs = ps.executeQuery();
        while (rs.next()) {
            Timestamp ts = rs.getTimestamp("eventexception_date");
            Calendar cal = Calendar.getInstance();
            cal.setTime(ts);
            cal.set(Calendar.MILLISECOND, 0);
            ret.add(cal.getTime());
        }
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
    } finally {
        obmHelper.cleanup(null, ps, rs);
    }
    return ret;
}

From source file:com.sfs.whichdoctor.dao.AddressDAOImpl.java

/**
 * Load the address bean./*from w w w.  ja  va2 s  .co m*/
 *
 * @param rs the rs
 *
 * @return the address bean
 *
 * @throws SQLException the SQL exception
 */
private AddressBean loadAddress(final ResultSet rs) throws SQLException {
    AddressBean address = new AddressBean();

    address.setId(rs.getInt("AddressId"));
    address.setGUID(rs.getInt("GUID"));
    address.setReferenceGUID(rs.getInt("ReferenceGUID"));
    address.setContactClass(rs.getString("ContactClass"));
    address.setContactType(rs.getString("ContactType"));
    address.setDescription(rs.getString("Description"));
    address.setAddressField(rs.getString("Address1"));
    address.setAddressField(rs.getString("Address2"));
    address.setAddressField(rs.getString("Address3"));
    address.setAddressField(rs.getString("Address4"));
    address.setAddressField(rs.getString("Address5"));
    address.setAddressField(rs.getString("Address6"));
    address.setAddressField(rs.getString("Address7"));

    address.setState(rs.getString("State"));
    address.setStateAbbreviation(rs.getString("StateAbbreviation"));
    address.setCountry(rs.getString("Country"));
    address.setCountryAbbreviation(rs.getString("CountryAbbreviation"));
    address.setRegion(rs.getString("Region"));

    address.setPrimary(rs.getBoolean("PrimaryAddress"));
    address.setReturnedMail(rs.getBoolean("ReturnedMail"));
    address.setRequestNoMail(rs.getBoolean("RequestNoMail"));
    address.setPostCode(rs.getString("PostCode"));
    address.setGeocode(rs.getString("Geocode"));
    address.setVerificationStatus(rs.getString("VerificationStatus"));

    address.setActive(rs.getBoolean("Active"));
    try {
        address.setCreatedDate(rs.getTimestamp("CreatedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error parsing CreatedDate: " + sqe.getMessage());
    }
    address.setCreatedBy(rs.getString("CreatedBy"));
    try {
        address.setModifiedDate(rs.getTimestamp("ModifiedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error parsing ModifiedDate: " + sqe.getMessage());
    }
    address.setModifiedBy(rs.getString("ModifiedBy"));
    try {
        address.setExportedDate(rs.getTimestamp("ExportedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error parsing ExportedDate: " + sqe.getMessage());
    }
    address.setExportedBy(rs.getString("ExportedBy"));

    return address;
}

From source file:com.chiorichan.database.DatabaseEngine.java

public static Map<String, Object> convertRow(ResultSet rs) throws SQLException {
    Map<String, Object> result = Maps.newLinkedHashMap();
    ResultSetMetaData rsmd = rs.getMetaData();

    int numColumns = rsmd.getColumnCount();

    for (int i = 1; i < numColumns + 1; i++) {
        String columnName = rsmd.getColumnName(i);

        // Loader.getLogger().info( "Column: " + columnName + " <-> " + rsmd.getColumnTypeName( i ) );

        if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
            result.put(columnName, rs.getArray(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.BIT) // Sometimes tinyints are read as bits
        {/*from  w ww  .j a  v a2 s . c  o m*/
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
            result.put(columnName, rs.getBoolean(columnName));
        } else if (rsmd.getColumnTypeName(i).contains("BLOB")
                || rsmd.getColumnType(i) == java.sql.Types.BINARY) {
            // BLOG = Max Length 65,535. Recommended that you use a LONGBLOG.
            byte[] bytes = rs.getBytes(columnName);
            result.put(columnName, bytes);
            /*
             * try
             * {
             * result.put( columnName, new String( bytes, "ISO-8859-1" ) );
             * }
             * catch ( UnsupportedEncodingException e )
             * {
             * e.printStackTrace();
             * }
             */
        } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
            result.put(columnName, rs.getDouble(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
            result.put(columnName, rs.getFloat(columnName));
        } else if (rsmd.getColumnTypeName(i).equals("INT")) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
            result.put(columnName, rs.getNString(columnName));
        } else if (rsmd.getColumnTypeName(i).equals("VARCHAR")) {
            result.put(columnName, rs.getString(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
            result.put(columnName, rs.getDate(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
            result.put(columnName, rs.getTimestamp(columnName));
        } else {
            result.put(columnName, rs.getObject(columnName));
        }
    }

    return result;
}

From source file:com.funambol.foundation.items.dao.PIMCalendarDAO.java

/**
 * Attaches the exception(s) to the recurrence rule of a calendar on the
 * basis of a ResultSet./*  ww  w.j a  va  2  s. co m*/
 *
 * @param cw the calendar (as a CalendarWrapper) still lacking information
 *           on the exceptions
 * @param rs the result of the execution of a proper SQL SELECT statement on
 *           the fnbl_pim_calendar_exception table, with the cursor before
 *           its first row
 * @return the CalendarWrapper object with address information attached
 * @throws Exception
 */
private CalendarWrapper addPIMCalendarExceptions(CalendarWrapper cw, ResultSet rs) throws Exception {

    if (cw.getCalendar().getCalendarContent().getRecurrencePattern() == null) {
        return cw;
    }

    SortedSet<ExceptionToRecurrenceRule> exceptions = new TreeSet<ExceptionToRecurrenceRule>();
    boolean allDay = cw.getCalendar().getCalendarContent().getAllDay().booleanValue();

    while (rs.next()) {

        String addition = rs.getString(SQL_FIELD_ADDITION);
        boolean isAddition = false;
        if (addition != null && addition.equals("1")) {
            isAddition = true;
        }
        String occurrenceDate;
        try {
            occurrenceDate = getStringFromDate(allDay,
                    new Date(rs.getTimestamp(SQL_FIELD_OCCURRENCE_DATE).getTime()));
        } catch (Exception e) {
            throw new SQLException(e.getLocalizedMessage());
        }

        ExceptionToRecurrenceRule etrr = new ExceptionToRecurrenceRule(isAddition, occurrenceDate);
        exceptions.add(etrr);
    }

    cw.getCalendar().getCalendarContent().getRecurrencePattern().setExceptions(exceptions);
    return cw;
}