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:fr.acxio.tools.agia.alfresco.HibernateNodeReader.java

/**
 * Retrieves nodes' IDs//  ww w . j  ava 2  s .c  o m
 * 
 * @return a collection of IDs
 */
private List<Long> retrieveKeys() {

    synchronized (lock) {
        MapSqlParameterSource aParams = new MapSqlParameterSource();
        aParams.addValue(JOBSTEP_PARAM, currentStep);
        return jdbcTemplate.query(sqlQuery, aParams, new ParameterizedRowMapper<Long>() {
            public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
                return rs.getLong(1);
            }
        });
    }

}

From source file:id.go.kemdikbud.tandajasa.dao.PegawaiDaoTest.java

@Test
public void testInsert() throws Exception {
    Golongan g = new Golongan();
    g.setId(99);/*from www .j  a  v  a  2 s  .  c om*/

    Pegawai p = new Pegawai();
    p.setNip("123");
    p.setNama("Endy Muhardin");
    p.setGolongan(g);

    DataSource ds = ctx.getBean(DataSource.class);
    Connection koneksiDatabase = ds.getConnection();

    PreparedStatement ps = koneksiDatabase.prepareStatement("select count(*) as jumlah from pegawai");
    ResultSet rsSebelum = ps.executeQuery();
    Assert.assertTrue(rsSebelum.next());
    Long jumlahRecordSebelum = rsSebelum.getLong(1);
    rsSebelum.close();

    PegawaiDao pd = (PegawaiDao) ctx.getBean("pegawaiDao");
    pd.save(p);

    ResultSet rsSetelah = ps.executeQuery();
    Assert.assertTrue(rsSetelah.next());
    Long jumlahRecordSetelah = rsSetelah.getLong("jumlah");
    rsSetelah.close();

    koneksiDatabase.close();
    Assert.assertEquals(new Long(jumlahRecordSebelum + 1), new Long(jumlahRecordSetelah));
}

From source file:mx.edu.um.escuela.dao.MaestroDaoJdbc.java

@Override
public Maestro mapRow(ResultSet rs, int i) throws SQLException {
    Maestro maestro = new Maestro();
    maestro.setId(rs.getLong("id"));
    maestro.setNomina(rs.getString("nomina"));
    maestro.setNombre(rs.getString("nombre"));
    maestro.setApellido(rs.getString("apellido"));
    if (rs.getDate("fecha_nacimiento") != null) {
        maestro.setFechaNacimiento(new Date(rs.getDate("fecha_nacimiento").getTime()));
    }//from   w w  w  .  ja va  2  s. c o  m
    maestro.setEsHombre(rs.getBoolean("es_hombre"));
    if (rs.getString("correo") != null) {
        maestro.setCorreo(rs.getString("correo"));
    }
    return maestro;
}

From source file:org.simbasecurity.core.task.VerifyAuditLogIntegrityTask.java

private RowMapper<VerifyAuditLogEvent> getRowMapper() {
    return new RowMapper<VerifyAuditLogEvent>() {
        @Override/* w ww.ja  v a 2s  . co m*/
        public VerifyAuditLogEvent mapRow(ResultSet rs, int rowNum) throws SQLException {
            VerifyAuditLogEvent event = new VerifyAuditLogEvent();
            event.setTimestamp(rs.getLong(TIME_STAMP));
            event.setUserName(rs.getString(USERNAME));
            event.setSsoToken(rs.getString(SSOTOKEN));
            event.setRemoteIp(rs.getString(REMOTE_IP));
            event.setMessage(rs.getString(MESSAGE));
            event.setName(rs.getString(NAME));
            event.setFirstName(rs.getString(FIRSTNAME));
            event.setUserAgent(rs.getString(USERAGENT));
            event.setHost(rs.getString(HOSTSERVERNAME));
            event.setEventCategory(rs.getString(EVENTCATEGORY));
            event.setDigest(rs.getString(DIGEST));
            event.setRequestUrl(rs.getString(REQUESTURL));
            event.setChainId(rs.getString(CHAINID));
            return event;
        }
    };
}

From source file:iddb.web.security.dao.SessionDAO.java

/**
 * @param session/*  w  ww  .  ja  v a  2  s . c o m*/
 * @param rs
 * @throws SQLException 
 */
private void loadSession(Session session, ResultSet rs) throws SQLException {
    session.setKey(rs.getString("id"));
    session.setUserId(rs.getLong("userid"));
    session.setIp(rs.getString("ip"));
    session.setCreated(rs.getDate("created"));
}

From source file:com.ewcms.component.comment.dao.CommentDAO.java

@Override
public List<Comment> findCommentPage(final int articleId, final int page, final int row) {
    String sql = "Select * From component_comment Where article_id = ? Limit ? OffSet ?";
    int offset = page * row;
    Object[] params = { articleId, row, offset };
    return jdbcTemplate.query(sql, params, new RowMapper<Comment>() {

        @Override/*from ww w. j a v a2s.c o m*/
        public Comment mapRow(ResultSet rs, int rowNum) throws SQLException {
            Comment comment = new Comment();
            comment.setId(rs.getLong("id"));
            comment.setArticleId(rs.getInt("article_id"));
            comment.setIp(rs.getString("ip"));
            comment.setUsername(rs.getString("username"));
            comment.setDate(rs.getTimestamp("date"));
            comment.setReplies(findReply(comment.getId()));
            return comment;
        }
    });
}

From source file:com.gvmax.data.queue.JDBCBasedQueueDAO.java

@Override
@Timed/*from ww w.j  a  v a  2 s.com*/
@ExceptionMetered
public List<QueueEntry<T>> getEntries(long since, int max) throws IOException {
    return jdbcTemplate.query("select * from " + tableName + " where id > ? limit " + max,
            new Object[] { since }, new RowMapper<QueueEntry<T>>() {
                @Override
                public QueueEntry<T> mapRow(ResultSet rs, int row) throws SQLException {
                    QueueEntry<T> entry = new QueueEntry<T>();
                    entry.setId(rs.getLong("id"));
                    entry.setEnqueuedDate(rs.getLong("enqueuedDate"));
                    try {
                        entry.setPayload(fromJson(rs.getString("payload")));
                    } catch (IOException e) {
                        throw new SQLException(e);
                    }
                    return entry;
                }
            });
}

From source file:mvc.dao.TarefaDAO.java

public Tarefa buscarTarefaPorId(Long id) {
    String sql = "select * from tarefas where id = ? ";
    try (PreparedStatement stmt = connection.prepareStatement(sql)) {
        stmt.setLong(1, id);/*from  w  ww  .j ava2  s  .  c o  m*/
        ResultSet rs = stmt.executeQuery();
        Tarefa tarefa = new Tarefa();
        if (rs.next()) {
            tarefa.setId(rs.getLong("id"));
            tarefa.setDescricao(rs.getString("descricao"));
            tarefa.setFinalizado(rs.getBoolean("finalizado"));
            //montando data
            Calendar data = Calendar.getInstance();
            if (rs.getDate("dataFinalizacao") != null) {
                data.setTime(rs.getDate("dataFinalizacao"));
                System.out.println("data");
                tarefa.setDataFinalizacao(data);
            }
        }
        return tarefa;
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.ingrid.importer.udk.strategy.v30.IDCStrategy3_0_0_fixErfassungsgrad.java

private void fixErfassungsgrad() throws Exception {
    if (log.isInfoEnabled()) {
        log.info("Fix \"Erfassungsgrad\" (t011_obj_geo.rec_grade) from Commission to Omission...");
    }/*from  w ww . ja v  a  2 s .  co  m*/

    // sql
    String sql = "select * from t011_obj_geo where rec_grade IS NOT NULL";

    PreparedStatement pS = jdbc.prepareStatement("UPDATE t011_obj_geo SET rec_grade = ? where id = ?");
    Statement st = jdbc.createStatement();
    ResultSet rs = jdbc.executeQuery(sql, st);
    int numFixed = 0;
    while (rs.next()) {
        long id = rs.getLong("id");
        long objId = rs.getLong("obj_id");
        double oldRecGrade = rs.getDouble("rec_grade");
        double newRecGrade = 100.0 - oldRecGrade;
        if (newRecGrade < 0.0) {
            newRecGrade = 0.0;
            log.warn("New value " + newRecGrade + " < 0, we set new value to 0.0.");
        }
        if (newRecGrade > 100.0) {
            newRecGrade = 100.0;
            log.warn("New value " + newRecGrade + " > 100, we set new value to 100.0.");
        }

        try {
            // round 2 decimals after digit
            newRecGrade = new BigDecimal(newRecGrade).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        } catch (Exception ex) {
            log.error("Problems rounding " + newRecGrade
                    + " to 2 decimals after digit, we keep unrounded value." + ex);
        }

        pS.setDouble(1, newRecGrade);
        pS.setLong(2, id);
        int numUpdated = pS.executeUpdate();
        if (log.isDebugEnabled()) {
            log.debug("Fixed t011_obj_geo.rec_grade from " + oldRecGrade + " to " + newRecGrade + " ("
                    + numUpdated + " row(s), objectId: " + objId + ")");
        }
        numFixed++;
    }

    pS.close();
    rs.close();
    st.close();

    if (log.isInfoEnabled()) {
        log.info("Fixed " + numFixed + " times \"Erfassungsgrad\"");
    }

    if (log.isInfoEnabled()) {
        log.info("Fix \"Erfassungsgrad\" (t011_obj_geo.rec_grade) from Commission to Omission...done");
    }
}

From source file:com.ethlo.kfka.mysql.TestCfg.java

@Bean
public KfkaMapStore<CustomKfkaMessage> mapStore(DataSource ds) {
    final RowMapper<CustomKfkaMessage> ROW_MAPPER = new RowMapper<CustomKfkaMessage>() {
        @Override//  www  .  jav a2 s  .  co m
        public CustomKfkaMessage mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new CustomKfkaMessageBuilder().userId(rs.getInt("userId")).payload(rs.getBytes("payload"))
                    .timestamp(rs.getLong("timestamp")).topic(rs.getString("topic")).type(rs.getString("type"))
                    .id(rs.getLong("id")).build();
        }
    };

    return new MysqlKfkaMapStore<CustomKfkaMessage>(ds, ROW_MAPPER);
}