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:com.carfinance.module.vehicleservicemanage.domain.VehicleContraceVehsInfoRowMapper.java

public VehicleContraceVehsInfo mapRow(ResultSet rs, int arg1) throws SQLException {
    VehicleContraceVehsInfo vehicleContraceVehsInfo = new VehicleContraceVehsInfo();

    vehicleContraceVehsInfo.setId(rs.getLong("id"));
    vehicleContraceVehsInfo.setContrace_id(rs.getLong("contrace_id"));
    vehicleContraceVehsInfo.setVehicle_id(rs.getLong("vehicle_id"));
    vehicleContraceVehsInfo.setLicense_plate(rs.getString("license_plate"));
    vehicleContraceVehsInfo.setModel(rs.getString("model"));
    vehicleContraceVehsInfo.setCompany(rs.getString("company"));
    vehicleContraceVehsInfo.setIsother(rs.getInt("isother"));
    vehicleContraceVehsInfo.setDriving_user_id(rs.getLong("driving_user_id"));
    vehicleContraceVehsInfo.setDriving_user_name(rs.getString("driving_user_name"));
    vehicleContraceVehsInfo.setDriving_user_license_no(rs.getString("driving_user_license_no"));
    vehicleContraceVehsInfo.setVehicle_price(rs.getDouble("vehicle_price"));
    vehicleContraceVehsInfo.setCreate_by(rs.getLong("create_by"));
    vehicleContraceVehsInfo.setCreate_at(rs.getDate("create_at"));
    vehicleContraceVehsInfo.setUpdate_by(rs.getLong("update_by"));
    vehicleContraceVehsInfo.setUpdate_at(rs.getDate("update_at"));

    try {/* ww  w.java 2 s.c om*/
        vehicleContraceVehsInfo.setKm(rs.getLong("km"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setOther_vehicle_km(rs.getLong("other_vehicle_km"));
    } catch (Exception e) {
    }

    try {
        if (rs.getTimestamp("return_time") != null) {
            String return_time_str = rs.getTimestamp("return_time").toString();
            vehicleContraceVehsInfo.setReturn_time(return_time_str.substring(0, return_time_str.length() - 2));
        }
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setReturn_km(rs.getLong("return_km"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setReturn_org(rs.getLong("return_org"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setOver_price(rs.getDouble("over_price"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setStatus(rs.getInt("status"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setEtc(rs.getString("etc"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setEtc_money(rs.getDouble("etc_money"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setOil_percent(rs.getInt("oil_percent"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setRevert_oil_percent(rs.getInt("revert_oil_percent"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setRevert_etc_money(rs.getInt("revert_etc_money"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setDaily_price(rs.getDouble("daily_price"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setSettlement_way(rs.getString("settlement_way"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setFixed_price(rs.getDouble("fixed_price"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setSystem_price(rs.getDouble("system_price"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setReduction_price(rs.getDouble("reduction_price"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setActually_price(rs.getDouble("actually_price"));
    } catch (Exception e) {
    }
    try {
        vehicleContraceVehsInfo.setTotal_actually(rs.getDouble("total_actually"));
    } catch (Exception e) {
    }

    try {
        vehicleContraceVehsInfo.setDispatch_status(rs.getInt("dispatch_status"));
    } catch (Exception e) {
    }

    return vehicleContraceVehsInfo;
}

From source file:gov.ca.cwds.es.live.RawClient.java

@Override
public RawClient read(final ResultSet rs) throws SQLException {
    super.read(rs);

    this.cltSensitivityIndicator = trimToNull(rs.getString(ColPos.CLT_SENSTV_IND.ordinal()));
    this.cltSoc158SealedClientIndicator = trimToNull(rs.getString(ColPos.CLT_SOC158_IND.ordinal()));
    this.cltBirthDate = rs.getDate(ColPos.CLT_BIRTH_DT.ordinal());
    this.cltClientIndexNumber = trimToNull(rs.getString(ColPos.CLT_CL_INDX_NO.ordinal()));
    this.cltCommonFirstName = (rs.getString(ColPos.CLT_COM_FST_NM.ordinal()));
    this.cltCommonLastName = trimToNull(rs.getString(ColPos.CLT_COM_LST_NM.ordinal()));
    this.cltCommonMiddleName = trimToNull(rs.getString(ColPos.CLT_COM_MID_NM.ordinal()));
    this.cltCreationDate = rs.getDate(ColPos.CLT_CREATN_DT.ordinal());
    this.cltDeathDate = rs.getDate(ColPos.CLT_DEATH_DT.ordinal());
    this.cltDeathDateVerifiedIndicator = trimToNull(rs.getString(ColPos.CLT_DTH_DT_IND.ordinal()));
    this.cltDriverLicenseNumber = trimToNull(rs.getString(ColPos.CLT_DRV_LIC_NO.ordinal()));
    this.cltDriverLicenseStateCodeType = rs.getShort(ColPos.CLT_D_STATE_C.ordinal());
    this.cltEmailAddress = trimToNull(rs.getString(ColPos.CLT_EMAIL_ADDR.ordinal()));
    this.cltEthUnableToDetReasonCode = trimToNull(rs.getString(ColPos.CLT_ETH_UD_CD.ordinal()));
    this.cltGenderCode = trimToNull(rs.getString(ColPos.CLT_GENDER_CD.ordinal()));
    this.cltHispUnableToDetReasonCode = trimToNull(rs.getString(ColPos.CLT_HISP_UD_CD.ordinal()));
    this.cltHispanicOriginCode = trimToNull(rs.getString(ColPos.CLT_HISP_CD.ordinal()));
    this.cltImmigrationStatusType = rs.getShort(ColPos.CLT_IMGT_STC.ordinal());
    this.cltLiterateCode = trimToNull(rs.getString(ColPos.CLT_LITRATE_CD.ordinal()));
    this.cltMaritalStatusType = rs.getShort(ColPos.CLT_MRTL_STC.ordinal());
    this.cltMilitaryStatusCode = trimToNull(rs.getString(ColPos.CLT_MILT_STACD.ordinal()));
    this.cltNamePrefixDescription = trimToNull(rs.getString(ColPos.CLT_NMPRFX_DSC.ordinal()));
    this.cltNameType = rs.getShort(ColPos.CLT_NAME_TPC.ordinal());

    this.cltPrimaryEthnicityType = rs.getShort(ColPos.CLT_P_ETHNCTYC.ordinal());
    this.cltPrimaryLanguageType = rs.getShort(ColPos.CLT_P_LANG_TPC.ordinal());
    this.cltSecondaryLanguageType = rs.getShort(ColPos.CLT_S_LANG_TC.ordinal());
    this.cltReligionType = rs.getShort(ColPos.CLT_RLGN_TPC.ordinal());

    this.cltSensitiveHlthInfoOnFileIndicator = trimToNull(rs.getString(ColPos.CLT_SNTV_HLIND.ordinal()));
    this.cltSoc158PlacementCode = trimToNull(rs.getString(ColPos.CLT_SOCPLC_CD.ordinal()));
    this.cltSocialSecurityNumChangedCode = trimToNull(rs.getString(ColPos.CLT_SSN_CHG_CD.ordinal()));
    this.cltSocialSecurityNumber = trimToNull(rs.getString(ColPos.CLT_SS_NO.ordinal()));
    this.cltSuffixTitleDescription = trimToNull(rs.getString(ColPos.CLT_SUFX_TLDSC.ordinal()));
    this.cltTribalAncestryClientIndicatorVar = trimToNull(rs.getString(ColPos.CLT_TRBA_CLT_B.ordinal()));
    this.cltZippyCreatedIndicator = trimToNull(rs.getString(ColPos.CLT_ZIPPY_IND.ordinal()));

    this.cltLastUpdatedId = trimToNull(rs.getString(ColPos.CLT_LST_UPD_ID.ordinal()));
    this.cltLastUpdatedTime = rs.getTimestamp(ColPos.CLT_LST_UPD_TS.ordinal());

    return this;
}

From source file:biblivre3.administration.ReportsDAO.java

public DelayedLendingsDto getLateReturnLendingsReportData() {
    DelayedLendingsDto dto = new DelayedLendingsDto();
    Connection con = null;/* w  w w.j av a2  s. com*/
    try {
        con = getDataSource().getConnection();
        final String sql = "SELECT u.userid, u.username, l.return_date, b.record "
                + "FROM lending l, users u, cataloging_biblio b, cataloging_holdings h "
                + "WHERE l.return_date < to_date(?, 'DD-MM-YYYY') " + "AND l.user_serial = u.userid "
                + "AND l.holding_serial = h.holding_serial " + "AND h.record_serial = b.record_serial ";
        final PreparedStatement st = con.prepareStatement(sql);
        st.setString(1, DateUtils.dd_MM_yyyy.format(new Date()));

        final ResultSet rs = st.executeQuery();
        List<String[]> data = new ArrayList<String[]>();

        while (rs.next()) {
            String[] lending = new String[4];
            lending[0] = String.valueOf(rs.getInt("userid")); // matricula do usuario
            lending[1] = rs.getString("username"); //nome do usuario
            lending[2] = Indexer
                    .listOneTitle(MarcUtils.iso2709ToRecord(new String(rs.getBytes("record"), "UTF-8"))); //titulo
            lending[3] = DateUtils.dd_MM_yyyy.format(rs.getDate("return_date"));
            data.add(lending);
        }
        dto.setData(data);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ExceptionUser("ERROR_REPORT_DAO_EXCEPTION");
    } finally {
        closeConnection(con);
    }

    return dto;
}

From source file:org.carlspring.tools.csv.dao.CSVDao.java

private String getField(ResultSet resultSet, int i, Field field) throws SQLException {
    // Handle primitives
    if (field.getType().equals("int")) {
        return String.valueOf(resultSet.getInt(i));
    } else if (field.getType().equals("long")) {
        return String.valueOf(resultSet.getLong(i));
    } else if (field.getType().equals("float")) {
        return String.valueOf(resultSet.getFloat(i));
    } else if (field.getType().equals("double")) {
        return String.valueOf(resultSet.getDouble(i));
    } else if (field.getType().equals("boolean")) {
        return String.valueOf(resultSet.getBoolean(i));
    }/*from w  w  w.jav a 2 s .  c  om*/
    // Handle objects
    else if (field.getType().equals("java.lang.String")) {
        return String.valueOf(resultSet.getString(i));
    } else if (field.getType().equals("java.sql.Date")) {
        return String.valueOf(resultSet.getDate(i));
    } else if (field.getType().equals("java.sql.Timestamp")) {
        return String.valueOf(resultSet.getTimestamp(i));
    } else if (field.getType().equals("java.math.BigDecimal")) {
        return String.valueOf(resultSet.getBigDecimal(i));
    }

    return null;
}

From source file:eionet.meta.dao.mysql.VocabularyConceptDAOImpl.java

/**
 * {@inheritDoc}//from w  w  w .ja v a 2  s. com
 */
@Override
public VocabularyConcept getVocabularyConcept(int vocabularyConceptId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("vocabularyConceptId", vocabularyConceptId);

    StringBuilder sql = new StringBuilder();
    sql.append(
            "select VOCABULARY_CONCEPT_ID, VOCABULARY_ID, IDENTIFIER, LABEL, DEFINITION, NOTATION, STATUS, ");
    sql.append("ACCEPTED_DATE, NOT_ACCEPTED_DATE, STATUS_MODIFIED ");
    sql.append("from VOCABULARY_CONCEPT where VOCABULARY_CONCEPT_ID=:vocabularyConceptId");

    VocabularyConcept result = getNamedParameterJdbcTemplate().queryForObject(sql.toString(), params,
            new RowMapper<VocabularyConcept>() {
                @Override
                public VocabularyConcept mapRow(ResultSet rs, int rowNum) throws SQLException {
                    VocabularyConcept vc = new VocabularyConcept();
                    vc.setId(rs.getInt("VOCABULARY_CONCEPT_ID"));
                    vc.setVocabularyId(rs.getInt("VOCABULARY_ID"));
                    vc.setIdentifier(rs.getString("IDENTIFIER"));
                    vc.setLabel(rs.getString("LABEL"));
                    vc.setDefinition(rs.getString("DEFINITION"));
                    vc.setNotation(rs.getString("NOTATION"));
                    vc.setStatus(rs.getInt("STATUS"));
                    vc.setAcceptedDate(rs.getDate("ACCEPTED_DATE"));
                    vc.setNotAcceptedDate(rs.getDate("NOT_ACCEPTED_DATE"));
                    vc.setStatusModified(rs.getDate("STATUS_MODIFIED"));
                    return vc;
                }
            });

    return result;
}

From source file:eionet.meta.dao.mysql.VocabularyConceptDAOImpl.java

/**
 * {@inheritDoc}/*ww w  .j a va2s. co m*/
 */
@Override
public VocabularyConcept getVocabularyConcept(int vocabularyFolderId, String conceptIdentifier) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("vocabularyFolderId", vocabularyFolderId);
    params.put("identifier", conceptIdentifier);

    StringBuilder sql = new StringBuilder();
    sql.append(
            "select VOCABULARY_CONCEPT_ID, VOCABULARY_ID, IDENTIFIER, LABEL, DEFINITION, NOTATION, STATUS, ");
    sql.append("ACCEPTED_DATE, NOT_ACCEPTED_DATE, STATUS_MODIFIED ");
    sql.append("from VOCABULARY_CONCEPT where VOCABULARY_ID=:vocabularyFolderId and IDENTIFIER=:identifier");

    VocabularyConcept result = getNamedParameterJdbcTemplate().queryForObject(sql.toString(), params,
            new RowMapper<VocabularyConcept>() {
                @Override
                public VocabularyConcept mapRow(ResultSet rs, int rowNum) throws SQLException {
                    VocabularyConcept vc = new VocabularyConcept();
                    vc.setId(rs.getInt("VOCABULARY_CONCEPT_ID"));
                    vc.setVocabularyId(rs.getInt("VOCABULARY_ID"));
                    vc.setIdentifier(rs.getString("IDENTIFIER"));
                    vc.setLabel(rs.getString("LABEL"));
                    vc.setDefinition(rs.getString("DEFINITION"));
                    vc.setNotation(rs.getString("NOTATION"));
                    vc.setStatus(rs.getInt("STATUS"));
                    vc.setAcceptedDate(rs.getDate("ACCEPTED_DATE"));
                    vc.setNotAcceptedDate(rs.getDate("NOT_ACCEPTED_DATE"));
                    vc.setStatusModified(rs.getDate("STATUS_MODIFIED"));
                    return vc;
                }
            });

    return result;
}

From source file:at.alladin.rmbt.statisticServer.UsageJSONResource.java

/**
 * Returns the statistics for used network name for a specific timespan [begin, end)
 * @param begin select all tests with time >= begin
 * @param end select all tests with time < end
 * @return the structurized JSON object//from   www .j av a2s .co  m
 * @throws SQLException
 * @throws JSONException
 */
private JSONObject getNetworkGroupName(Timestamp begin, Timestamp end) throws SQLException, JSONException {
    JSONObject returnObj = new JSONObject();
    JSONArray sums = new JSONArray();
    JSONArray values = new JSONArray();
    returnObj.put("sums", sums);
    returnObj.put("values", values);

    HashMap<String, Long> fieldSums = new HashMap<>();

    PreparedStatement ps;
    ResultSet rs;

    final String sql = "SELECT date_trunc('day', time) _day, COALESCE(network_group_name,'null') \"version\", count(network_group_name) count_group_name"
            + " FROM test" + " WHERE status='FINISHED' AND deleted=false AND time >= ? AND time < ?"
            + " GROUP BY _day, network_group_name " + " HAVING count(network_group_name) > 0 "
            + " ORDER BY _day ASC";

    ps = conn.prepareStatement(sql);
    ps.setTimestamp(1, begin);
    ps.setTimestamp(2, end);

    rs = ps.executeQuery();

    //one array-item for each day
    long currentTime = -1;
    JSONObject currentEntry = null;
    JSONArray currentEntryValues = null;
    while (rs.next()) {

        //new item, of a new day is reached
        long newTime = rs.getDate("_day").getTime();
        if (currentTime != newTime) {
            currentTime = newTime;
            currentEntry = new JSONObject();
            currentEntryValues = new JSONArray();
            currentEntry.put("day", rs.getDate("_day").getTime());
            currentEntry.put("values", currentEntryValues);
            values.put(currentEntry);
        }

        //disable null-values
        String version = rs.getString("version");
        long count = rs.getLong("count_group_name");
        if (version.isEmpty()) {
            version = "empty";
        }

        //add value to sum
        if (!fieldSums.containsKey(version)) {
            fieldSums.put(version, new Long(0));
        }
        fieldSums.put(version, fieldSums.get(version) + count);

        JSONObject current = new JSONObject();
        current.put("field", version);
        current.put("value", count);
        currentEntryValues.put(current);
    }

    rs.close();
    ps.close();

    //add field sums
    for (String field : fieldSums.keySet()) {
        JSONObject obj = new JSONObject();
        obj.put("field", field);
        obj.put("sum", fieldSums.get(field));
        sums.put(obj);
    }

    return returnObj;
}

From source file:at.alladin.rmbt.statisticServer.UsageJSONResource.java

/**
 * Returns the statistics for used network type for a specific timespan [begin, end)
 * @param begin select all tests with time >= begin
 * @param end select all tests with time < end
 * @return the structurized JSON object//from  www. j a  v  a  2  s.c o  m
 * @throws SQLException
 * @throws JSONException
 */
private JSONObject getNetworkGroupType(Timestamp begin, Timestamp end) throws SQLException, JSONException {
    JSONObject returnObj = new JSONObject();
    JSONArray sums = new JSONArray();
    JSONArray values = new JSONArray();
    returnObj.put("sums", sums);
    returnObj.put("values", values);

    HashMap<String, Long> fieldSums = new HashMap<>();

    PreparedStatement ps;
    ResultSet rs;

    final String sql = "SELECT date_trunc('day', time) _day, COALESCE(network_group_type,'null') \"version\", count(network_group_type) count_group_type"
            + " FROM test" + " WHERE status='FINISHED' AND deleted=false AND time >= ? AND time < ?"
            + " GROUP BY _day, network_group_type " + " HAVING count(network_group_type) > 0 "
            + " ORDER BY _day ASC";

    ps = conn.prepareStatement(sql);
    ps.setTimestamp(1, begin);
    ps.setTimestamp(2, end);

    rs = ps.executeQuery();

    //one array-item for each day
    long currentTime = -1;
    JSONObject currentEntry = null;
    JSONArray currentEntryValues = null;
    while (rs.next()) {

        //new item, of a new day is reached
        long newTime = rs.getDate("_day").getTime();
        if (currentTime != newTime) {
            currentTime = newTime;
            currentEntry = new JSONObject();
            currentEntryValues = new JSONArray();
            currentEntry.put("day", rs.getDate("_day").getTime());
            currentEntry.put("values", currentEntryValues);
            values.put(currentEntry);
        }

        //disable null-values
        String version = rs.getString("version");
        long count = rs.getLong("count_group_type");
        if (version.isEmpty()) {
            version = "empty";
        }

        //add value to sum
        if (!fieldSums.containsKey(version)) {
            fieldSums.put(version, new Long(0));
        }
        fieldSums.put(version, fieldSums.get(version) + count);

        JSONObject current = new JSONObject();
        current.put("field", version);
        current.put("value", count);
        currentEntryValues.put(current);
    }

    rs.close();
    ps.close();

    //add field sums
    for (String field : fieldSums.keySet()) {
        JSONObject obj = new JSONObject();
        obj.put("field", field);
        obj.put("sum", fieldSums.get(field));
        sums.put(obj);
    }

    return returnObj;
}

From source file:com.wso2telco.dep.reportingservice.dao.TaxDAO.java

/**
 * Gets the API request times for application.
 *
 * @param consumerKey the consumer key//  ww  w. j ava2 s . com
 * @param year the year
 * @param month the month
 * @param userId the user id
 * @return the API request times for application
 * @throws Exception the exception
 */
public Map<String, List<APIRequestDTO>> getAPIRequestTimesForApplication(String consumerKey, short year,
        short month, String userId) throws Exception {
    Connection connection = null;
    PreparedStatement ps = null;
    ResultSet results = null;
    String sql = "SELECT api_version,total_request_count AS count,STR_TO_DATE(time,'%Y-%m-%d') as date FROM  "
            + ReportingTable.API_REQUEST_SUMMARY + "WHERE consumerKey=?  AND userId=? AND month=? AND year=?;";

    Map<String, List<APIRequestDTO>> apiRequests = new HashMap<String, List<APIRequestDTO>>();
    try {
        connection = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB);
        ps = connection.prepareStatement(sql);
        ps.setString(1, consumerKey);
        ps.setString(2, userId);
        ps.setShort(3, month);
        ps.setShort(4, year);

        log.debug("SQL (PS) st ---> " + ps.toString());
        results = ps.executeQuery();
        log.debug("SQL (PS) ed ---> ");

        while (results.next()) {
            APIRequestDTO req = new APIRequestDTO();
            req.setApiVersion(results.getString("api_version"));
            req.setRequestCount(results.getInt("count"));
            req.setDate(results.getDate("date"));
            if (apiRequests.containsKey(req.getApiVersion())) {
                apiRequests.get(req.getApiVersion()).add(req);
            } else {
                List<APIRequestDTO> list = new ArrayList<APIRequestDTO>();
                list.add(req);
                apiRequests.put(req.getApiVersion(), list);
            }
        }
    } catch (SQLException e) {
        handleException("Error occurred while getting Request Times for Application", e);
    } finally {
        DbUtils.closeAllConnections(ps, connection, results);
    }

    return apiRequests;
}

From source file:gr.seab.r2rml.beans.Generator.java

private String getStringValue(String field, ResultSet rs) {
    String result = null;//from w  ww  .j av a  2  s.  co m
    try {
        if (rs.getObject(field) == null)
            return null;

        BaseDatatype fieldDataType = findFieldDataType(field, rs);

        if (fieldDataType != null && fieldDataType.getURI().equals(XSDDatatype.XSDdate.getURI())) {
            result = xsdDateFormat.format(rs.getDate(field));
        } else {
            result = rs.getString(field);
        }
    } catch (Exception e) {
        log.error("Failed to get value as string for column " + field, e);
    }
    return result;
}