Example usage for java.sql ResultSet getDate

List of usage examples for java.sql ResultSet getDate

Introduction

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

Prototype

java.sql.Date getDate(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.Date object in the Java programming language.

Usage

From source file:ems.emsystem.dao.JDBCEmployeeDAOImpl.java

private Employee getEmployeeFromResultSet(ResultSet rs) throws SQLException {
    Employee em = new Employee();
    em.setId(rs.getLong("ID"));
    em.setActive(rs.getBoolean("ACTIVE"));
    em.setBirthdate(rs.getDate("BIRTHDATE"));
    em.setFirstname(rs.getString("FIRSTNAME"));
    em.setLastname(rs.getString("LASTNAME"));
    em.setSalary(rs.getDouble("SALARY"));
    long dep_id = rs.getLong("DEPARTMENT");
    Department dep = departmentDAO.getDepartment(dep_id);
    em.setDepartment(dep);//from  ww  w .  ja  v a  2  s  .  c  o m
    return em;
}

From source file:org.inbio.ait.jdbc.mapper.DwcMapper.java

@Override
public SpecimenBase mapRow(ResultSet rs, int rowNum) throws SQLException {
    SpecimenBase sp = new SpecimenBase();
    //Mandatory data
    sp.setGlobaluniqueidentifier(rs.getString(ph.getGlobaluniqueidentifier()));
    sp.setDatelastmodified(rs.getDate(ph.getDatelastmodified()));
    sp.setInstitutioncode(rs.getString(ph.getInstitutioncode()));
    sp.setCollectioncode(rs.getString(ph.getCollectioncode()));
    sp.setCatalognumber(rs.getString(ph.getCatalognumber()));
    sp.setScientificname(rs.getString(ph.getScientificname()));
    sp.setBasisofrecord(rs.getString(ph.getBasisofrecord()));
    //Aditional data
    if (!ph.getKingdom().equals("unmapped")) {
        sp.setKingdom(rs.getString(ph.getKingdom()));
    }/*  www  . java  2  s .  c om*/
    if (!ph.getPhylum().equals("unmapped")) {
        sp.setPhylum(rs.getString(ph.getPhylum()));
    }
    if (!ph.getClass1().equals("unmapped")) {
        sp.setClass1(rs.getString(ph.getClass1()));
    }
    if (!ph.getOrders().equals("unmapped")) {
        sp.setOrders(rs.getString(ph.getOrders()));
    }
    if (!ph.getFamily().equals("unmapped")) {
        sp.setFamily(rs.getString(ph.getFamily()));
    }
    if (!ph.getGenus().equals("unmapped")) {
        sp.setGenus(rs.getString(ph.getGenus()));
    }
    if (!ph.getSpecificepithet().equals("unmapped")) {
        sp.setSpecificepithet(rs.getString(ph.getSpecificepithet()));
    }
    if (!ph.getDecimallongitude().equals("unmapped")) {
        sp.setDecimallongitude(rs.getString(ph.getDecimallongitude()));
    }
    if (!ph.getDecimallatitude().equals("unmapped")) {
        sp.setDecimallatitude(rs.getString(ph.getDecimallatitude()));
    }
    return sp;
}

From source file:com.cloudera.sqoop.mapreduce.db.DateSplitter.java

/**
    Retrieve the value from the column in a type-appropriate manner and
    return its timestamp since the epoch. If the column is null, then return
    Long.MIN_VALUE.  This will cause a special split to be generated for the
    NULL case, but may also cause poorly-balanced splits if most of the
    actual dates are positive time since the epoch, etc.
  *///from   w  ww.j  a  va2  s .  co  m
private long resultSetColToLong(ResultSet rs, int colNum, int sqlDataType) throws SQLException {
    try {
        switch (sqlDataType) {
        case Types.DATE:
            return rs.getDate(colNum).getTime();
        case Types.TIME:
            return rs.getTime(colNum).getTime();
        case Types.TIMESTAMP:
            return rs.getTimestamp(colNum).getTime();
        default:
            throw new SQLException("Not a date-type field");
        }
    } catch (NullPointerException npe) {
        // null column. return minimum long value.
        LOG.warn("Encountered a NULL date in the split column. " + "Splits may be poorly balanced.");
        return Long.MIN_VALUE;
    }
}

From source file:co.nubetech.apache.hadoop.DateSplitter.java

/**
 * Retrieve the value from the column in a type-appropriate manner and
 * return its timestamp since the epoch. If the column is null, then return
 * Long.MIN_VALUE. This will cause a special split to be generated for the
 * NULL case, but may also cause poorly-balanced splits if most of the
 * actual dates are positive time since the epoch, etc.
 *///ww w. ja va  2s.  c  o  m
private long resultSetColToLong(ResultSet rs, int colNum, int sqlDataType) throws SQLException {
    try {
        switch (sqlDataType) {
        case Types.DATE:
            return rs.getDate(colNum).getTime();
        case Types.TIME:
            return rs.getTime(colNum).getTime();
        case Types.TIMESTAMP:
            return rs.getTimestamp(colNum).getTime();
        default:
            throw new SQLException("Not a date-type field");
        }
    } catch (NullPointerException npe) {
        // null column. return minimum long value.
        LOG.warn("Encountered a NULL date in the split column. Splits may be poorly balanced.");
        return Long.MIN_VALUE;
    }
}

From source file:com.ewcms.content.particular.dao.FrontProjectArticleDAO.java

private ProjectArticle interactionRowMapper(ResultSet rs) throws SQLException {
    ProjectArticle vo = new ProjectArticle();
    vo.setId(rs.getLong("id"));
    vo.setDense(Dense.valueOf(rs.getString("dense")));
    vo.setPublished(rs.getDate("published"));
    vo.setProjectBasic(frontProjectBasicDAO.get(rs.getLong("project_basic_code")));
    return vo;//  w  ww.  ja  v  a 2s .co m
}

From source file:com.abixen.platform.module.chart.service.impl.AbstractDatabaseService.java

private DataSourceValueWeb getValueAsDataSourceValueDateWeb(ResultSet row, String columnName)
        throws SQLException {
    Date value = row.getDate(row.findColumn(columnName));
    return new DataSourceValueDateWeb() {
        @Override/*from w ww  . j  a  v  a2s  .c o m*/
        public Date getValue() {
            return value;
        }

        @Override
        public void setValue(Date value) {
            throw new NotImplementedException("Setter not implemented yet");
        }
    };
}

From source file:connectKiosk.Query.java

public void getUserVisits(String email) throws SQLException {

    //statement is hardcoded, only takes the email
    String query = "SELECT users.email, users.fname, users.lname, visits.email, "
            + "visits.visitDate, visits.reason " + " FROM users" + " INNER JOIN visits" + " WHERE users.email='"
            + email + "'" + " ORDER BY visits.visitDate";

    //get results of query
    ResultSet rs = stmt.executeQuery(query);

    //print each line of the query
    while (rs.next()) {
        System.out.print(rs.getString("users.email") + " | " + rs.getString("users.lname") + " | "
                + rs.getDate("visitDate") + " | " + rs.getTime("visitDate") + " | " + rs.getString("reason"));

        System.out.println();/*from   ww w  .j  a  v a2 s.  co m*/
    }
}

From source file:com.surveypanel.dao.FormRowHandler.java

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    FormDTO formDTO = new FormDTO();
    formDTO.setId(rs.getString("id"));
    formDTO.setSurveyId(rs.getLong("surveyId"));
    formDTO.setQualified(rs.getBoolean("qualified"));
    formDTO.setFinish(rs.getBoolean("finish"));
    formDTO.setUpdated(rs.getDate("updated"));
    formDTO.setCreated(rs.getDate("created"));
    formDTO.setVariables(StateRowMapper.getMap(rs.getBlob("js_data")));
    formDTO.setXmlContent(rs.getString("xml_data"));
    return formDTO;
}

From source file:info.naiv.lab.java.tool.sqlite.exporter.component.ValueHandlerImpl.java

/**
 *
 * @param field//from ww  w .  j a va  2 s  .c  o m
 * @param rowSet
 * @return
 * @throws SQLException
 */
@Override
public Object handleValue(Field field, ResultSet rowSet) throws SQLException {
    String name = field.getOriginalName();
    switch (field.getTypeInfo()) {
    case CHAR:
    case NCHAR:
        return StringUtils.trimTrailingWhitespace(rowSet.getString(name));
    case DATE:
        return Objects.toString(rowSet.getDate(name), null);
    case TIME:
        return Objects.toString(rowSet.getTime(name), null);
    case TIMESTAMP:
        return Objects.toString(rowSet.getTimestamp(name), null);
    default:
        return rowSet.getObject(name);
    }
}

From source file:com.nabla.dc.server.handler.fixed_asset.UpdateAssetDisposalHandler.java

@Override
protected void update(final UpdateAssetDisposal cmd, final IUserSessionContext ctx)
        throws DispatchException, SQLException {
    final ValidationException errors = new ValidationException();
    if (!Asset.validate(cmd, getAssetAcqisitionDate(ctx.getReadConnection(), cmd.getId()), null, errors))
        throw errors;
    // retrieve current disposal date if any and company ID for this asset
    Date oldDisposalDate;/*  w w  w  .j  ava  2 s  .com*/
    Integer companyId;
    final PreparedStatement stmt = StatementFormat.prepare(ctx.getReadConnection(),
            "SELECT t.disposal_date, c.company_id"
                    + " FROM fa_asset AS t INNER JOIN fa_company_asset_category AS c ON c.id=t.fa_company_asset_category_id"
                    + " WHERE t.id=?;",
            cmd.getId());
    try {
        final ResultSet rs = stmt.executeQuery();
        try {
            if (!rs.next())
                throw new ActionException(CommonServerErrors.RECORD_HAS_BEEN_REMOVED);
            oldDisposalDate = rs.getDate(1);
            companyId = rs.getInt(2);
        } finally {
            rs.close();
        }
    } finally {
        stmt.close();
    }
    final ConnectionTransactionGuard guard = new ConnectionTransactionGuard(ctx.getWriteConnection());
    try {
        // update asset record
        sql.execute(guard.getConnection(), cmd);
        if (oldDisposalDate != null && cmd.getDate() != oldDisposalDate) {
            if (log.isDebugEnabled())
                log.debug("reverting old disposal data");
            RevertAssetDisposalHandler.revertDisposal(guard.getConnection(), cmd.getId());
        }
        if (oldDisposalDate == null || cmd.getDate() != oldDisposalDate) {
            if (log.isDebugEnabled())
                log.debug("disposing asset...");
            Asset.dispose(guard.getConnection(), cmd.getId(), cmd);
            UserPreference.save(ctx, companyId, IAsset.DISPOSAL_PREFERENCE_GROUP, "disposal_date",
                    cmd.getDate());
            UserPreference.save(ctx, companyId, IAsset.DISPOSAL_PREFERENCE_GROUP, "disposal_type",
                    cmd.getType());
        }
        guard.setSuccess();
    } finally {
        guard.close();
    }
}