Example usage for java.sql ResultSet getLong

List of usage examples for java.sql ResultSet getLong

Introduction

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

Prototype

long getLong(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

From source file:nl.surfnet.coin.teams.service.impl.TeamExternalGroupDaoImpl.java

@Override
public ExternalGroup getExternalGroupByIdentifier(String identifier) {
    Object[] args = { identifier };

    try {/* ww w  .  j  a  v  a 2 s.  c  om*/
        return this.jdbcTemplate.queryForObject("SELECT * FROM external_groups AS eg WHERE eg.identifier = ?",
                args, new RowMapper<ExternalGroup>() {
                    @Override
                    public ExternalGroup mapRow(ResultSet rs, int rowNum) throws SQLException {

                        final ExternalGroup e = new ExternalGroup();
                        e.setId(rs.getLong("id"));
                        e.setIdentifier(rs.getString(IDENTIFIER));
                        e.setDescription(rs.getString(DESCRIPTION));
                        e.setName(rs.getString(NAME));
                        e.setGroupProviderIdentifier(rs.getString(GROUP_PROVIDER));
                        return e;
                    }
                });
    } catch (EmptyResultDataAccessException er) {
        return null;
    }
}

From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java

@Test
public void loadEventSession() throws SQLException {
    long eventId = eventLoaderRepository.loadEvent(
            new EventData(1, "Test Event", "Test Event Description", "test", "2012-10-15T00:00:00",
                    "2012-10-18T23:59:59", "America/New_York", "NFJS", 297),
            new VenueData("Some Fancy Hotel", "1234 North Street, Chicago, IL 60605", 41.89001, -87.677765,
                    "It's in Illinois"));
    long timeSlotId = eventLoaderRepository.loadTimeSlot(new TimeSlotData(eventId, "Time Slot 1",
            "2012-10-15T00:00:00", "2012-10-18T23:59:59", "NFJS", 6296));

    int eventSessionId = 1;
    List<Long> leaderIds = Collections.emptyList();
    eventLoaderRepository.loadEventSession(new EventSessionData(eventId, eventSessionId, "What's new in Spring",
            "Come find out what's new in Spring", "#newspring", 1L, timeSlotId, "NFJS", 24409L, leaderIds));
    jdbcTemplate.queryForObject(/*from ww  w . jav a  2  s.c o m*/
            "select event, id, title, description, hashtag, venue, timeslot from EventSession where event=? and id=?",
            new RowMapper<ResultSet>() {
                public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException {
                    assertEquals(1L, rs.getLong("event"));
                    assertEquals(1L, rs.getLong("id"));
                    assertEquals("What's new in Spring", rs.getString("title"));
                    assertEquals("Come find out what's new in Spring", rs.getString("description"));
                    assertEquals("#newspring", rs.getString("hashtag"));
                    assertEquals(1, rs.getLong("venue"));
                    assertEquals(1, rs.getLong("timeslot"));
                    return null;
                }
            }, eventId, eventSessionId);
}

From source file:com.flexive.core.storage.H2.H2SequencerStorage.java

/**
 * {@inheritDoc}//  w w  w .j  a  v  a 2s  .  c om
 */
@Override
public long getCurrentId(FxSystemSequencer sequencer) throws FxApplicationException {
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = Database.getDbConnection();
        ps = con.prepareStatement(SQL_GET_CURRVALUE);
        ps.setString(1, H2_SEQ_PREFIX + sequencer.getSequencerName());
        ResultSet rs = ps.executeQuery();
        if (rs != null && rs.next())
            return rs.getLong(1);
    } catch (SQLException exc) {
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage());
    } finally {
        Database.closeObjects(H2SequencerStorage.class, con, ps);
    }
    throw new FxCreateException(LOG, "ex.sequencer.notFound", sequencer.getSequencerName());
}

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 {//from   ww  w  . j a  v a  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:io.apiman.manager.api.jdbc.handlers.ResponseStatsPerPlanHandler.java

/**
 * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
 *//* w  ww  .j a  va2s . c o m*/
@Override
public ResponseStatsPerPlanBean handle(ResultSet rs) throws SQLException {
    ResponseStatsPerPlanBean rval = new ResponseStatsPerPlanBean();
    while (rs.next()) {
        String plan = rs.getString(1);
        if (plan == null) {
            continue;
        }
        String rtype = rs.getString(2);
        long count = rs.getLong(3);

        ResponseStatsDataPoint dataPoint = rval.getData().get(plan);
        if (dataPoint == null) {
            dataPoint = new ResponseStatsDataPoint();
            rval.getData().put(plan, dataPoint);
        }

        if (rtype == null) {
            dataPoint.setTotal(dataPoint.getErrors() + dataPoint.getFailures() + count);
        } else if (rtype.equals("failure")) { //$NON-NLS-1$
            dataPoint.setTotal(dataPoint.getTotal() + count);
            dataPoint.setFailures(count);
        } else if (rtype.equals("error")) { //$NON-NLS-1$
            dataPoint.setTotal(dataPoint.getTotal() + count);
            dataPoint.setErrors(count);
        }
    }
    return rval;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.jdbc.QuartzJobHistoryQueriesImpl.java

public QuartzJobHistoryQueriesImpl() {

    quartzJobHistoryRowMapper = new ParameterizedRowMapper<QuartzJobHistory>() {

        public QuartzJobHistory mapRow(final ResultSet resultSet, final int i) throws SQLException {

            final Long jobWSSubmissionDateAsLong = resultSet.getLong(QuartzJobHistory.JOB_WS_SUBMISSION_DATE);
            Date jobWSSubmissionDate = null;

            // if 0L is found, it means the job was not submitted through the web service (and converting that would give us The Epoch ...)
            if (jobWSSubmissionDateAsLong != 0L) {
                jobWSSubmissionDate = new Date(jobWSSubmissionDateAsLong);
            }/*from w  ww .ja v  a  2  s.  c o m*/

            final QuartzJobHistory quartzJobHistory = new QuartzJobHistory(resultSet.getString(JOB_NAME),
                    resultSet.getString(JOB_GROUP), resultSet.getDate(FIRE_TIME),
                    QuartzJobStatus.valueOf(resultSet.getString(STATUS)), resultSet.getDate(LAST_UPDATED),
                    resultSet.getString(QuartzJobHistory.LINK_TEXT),
                    Long.parseLong(resultSet.getString(QuartzJobHistory.ESTIMATED_UNCOMPRESSED_SIZE)),
                    jobWSSubmissionDate);
            quartzJobHistory.setQueueName(resultSet.getString(QUEUE_NAME));
            quartzJobHistory.setEnqueueDate(resultSet.getTimestamp(TIME_ENQUEUED));
            return quartzJobHistory;
        }
    };
}

From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet2.java

/**
 * @param connection//from  w  w  w . jav  a  2 s.co  m
 * @param series
 * @param metrica
 * @param timeBegin
 * @param timeEnd
 * @param dataset
 * @throws SQLException
 */
private void getMetrics(Connection connection, String series, String metrica, Calendar calendarBegin,
        Calendar calendarEnd, DefaultCategoryDataset dataset) throws SQLException {

    PreparedStatement stmt = null;
    try {

        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");

        Calendar calendar1 = (Calendar) calendarBegin.clone();
        String dateStr = format.format(calendar1.getTime());
        dataset.addValue(0, series, dateStr);
        for (int i = 0; i < 6; i++) {
            calendar1.add(Calendar.DAY_OF_MONTH, 1);
            dateStr = format.format(calendar1.getTime());
            dataset.addValue(0, series, dateStr);
        }

        stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE"
                + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? ");

        stmt.setString(1, metrica);
        stmt.setDate(2, new java.sql.Date(calendarBegin.getTimeInMillis()));
        stmt.setDate(3, new java.sql.Date(calendarEnd.getTimeInMillis()));
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            long value = rs.getLong("METRIC_VALUE_LONG");
            Date date = rs.getDate("METRIC_DATE");
            dateStr = format.format(date.getTime());
            String category = dateStr;
            dataset.addValue(value, series, category);
            //            System.out.println(value + " = " + series + " = "+ category);
        }
        rs.close();

    } finally {
        if (stmt != null)
            stmt.close();
    }
}

From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java

/**
 * @param connection//from   ww  w  . j ava  2s  .c  o m
 * @param series
 * @param metrica
 * @param timeBegin
 * @param timeEnd
 * @param dataset
 * @throws SQLException
 */
private void getMetrics(Connection connection, String series, String metrica, Calendar calendarBegin,
        Calendar calendarEnd, DefaultCategoryDataset dataset) throws SQLException {

    PreparedStatement stmt = null;
    try {

        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");

        Calendar calendar1 = (Calendar) calendarBegin.clone();
        String dateStr = format.format(calendar1.getTime());
        dataset.addValue(0, series, dateStr);
        for (int i = 0; i < 6; i++) {
            calendar1.add(Calendar.DAY_OF_MONTH, 1);
            dateStr = format.format(calendar1.getTime());
            dataset.addValue(0, series, dateStr);
        }

        stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE"
                + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? ");

        stmt.setString(1, metrica);
        stmt.setDate(2, new java.sql.Date(calendarBegin.getTimeInMillis()));
        stmt.setDate(3, new java.sql.Date(calendarEnd.getTimeInMillis()));
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            long value = rs.getLong("METRIC_VALUE_LONG") / 1000;
            Date date = rs.getDate("METRIC_DATE");
            dateStr = format.format(date.getTime());
            String category = dateStr;
            dataset.addValue(value, series, category);
            //            System.out.println(value + " = " + series + " = "+ category);
        }
        rs.close();

    } finally {
        if (stmt != null)
            stmt.close();
    }
}

From source file:com.oracle2hsqldb.dialect.Oracle9Dialect.java

/**
 * Superclass returns nothing.//from  ww  w .  ja va2  s.  co  m
 */
public Iterator getSequences(DataSource dataSource, String schemaName) throws SQLException {
    final List seq = new LinkedList();
    new JdbcTemplate(dataSource).query("SELECT sequence_name, last_number FROM user_sequences",
            new RowCallbackHandler() {
                public void processRow(ResultSet rs) throws SQLException {
                    String seqName = rs.getString("SEQUENCE_NAME");
                    long seqValue = rs.getLong("LAST_NUMBER");
                    if (log.isDebugEnabled())
                        log.debug("Reading sequence " + seqName + "; currval=" + seqValue);
                    seq.add(new Sequence(seqName, new Long(seqValue)));
                }
            });
    return seq.iterator();
}

From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java

@Test
public void updateTimeSlot() throws SQLException {
    long eventId = eventLoaderRepository.loadEvent(
            new EventData(1, "Test Event", "Test Event Description", "test", "2012-10-15T00:00:00",
                    "2012-10-18T23:59:59", "America/New_York", "NFJS", 297),
            new VenueData("Some Fancy Hotel", "1234 North Street, Chicago, IL 60605", 41.89001, -87.677765,
                    "It's in Illinois"));

    long timeSlotId = eventLoaderRepository.loadTimeSlot(new TimeSlotData(eventId, "Time Slot 1",
            "2012-10-15T00:00:00", "2012-10-18T23:59:59", "NFJS", 6296));
    assertEquals(1L, timeSlotId);/*www.j av a 2 s . c o m*/
    jdbcTemplate.queryForObject("select id, event, label, startTime, endTime from EventTimeSlot where id=?",
            new RowMapper<ResultSet>() {
                public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException {
                    assertEquals(1L, rs.getLong("id"));
                    assertEquals(1L, rs.getLong("event"));
                    Timestamp startTime = rs.getTimestamp("startTime");
                    Timestamp endTime = rs.getTimestamp("endTime");
                    //            assertEquals(new DateTime(2012, 10, 15, 0, 0, 0, 0, DateTimeZone.getDefault()).getMillis(), startTime.getTime());
                    //            assertEquals(new DateTime(2012, 10, 18, 23, 59, 59, 0, DateTimeZone.getDefault()).getMillis(), endTime.getTime());
                    return null;
                }
            }, timeSlotId);

    long updatedTimeSlotId = eventLoaderRepository.loadTimeSlot(new TimeSlotData(eventId, "Time Slot One",
            "2012-10-15T01:00:00", "2012-10-15T02:30:00", "NFJS", 6296));
    assertEquals(1L, updatedTimeSlotId);
    jdbcTemplate.queryForObject("select id, event, label, startTime, endTime from EventTimeSlot where id=?",
            new RowMapper<ResultSet>() {
                public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException {
                    assertEquals(1L, rs.getLong("id"));
                    assertEquals(1L, rs.getLong("event"));
                    assertEquals("Time Slot One", rs.getString("label"));
                    Timestamp startTime = rs.getTimestamp("startTime");
                    Timestamp endTime = rs.getTimestamp("endTime");
                    //            assertEquals(new DateTime(2012, 10, 15, 1, 0, 0, 0, DateTimeZone.getDefault()).getMillis(), startTime.getTime());
                    //            assertEquals(new DateTime(2012, 10, 15, 2, 30, 0, 0, DateTimeZone.getDefault()).getMillis(), endTime.getTime());
                    return null;
                }
            }, updatedTimeSlotId);
}