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:tianci.pinao.dts.dao.impl.ConfigDaoImpl.java

@Override
public Config mapRow(ResultSet rs, int index) throws SQLException {
    Config config = new Config();

    config.setId(rs.getInt("id"));
    config.setType(rs.getInt("type"));
    config.setValue(rs.getLong("value"));
    Timestamp ts = rs.getTimestamp("lastmod_time");
    if (ts != null)
        config.setLastModTime(new Date(ts.getTime()));
    config.setLastModUserid(rs.getInt("lastmod_userid"));

    return config;
}

From source file:com.persistent.cloudninja.mapper.MeteringTotalsEntityRowMapper.java

@Override
public Usage mapRow(ResultSet rs, int row) throws SQLException {

    Usage mte = new Usage();

    mte.setYear(rs.getInt("Year"));

    mte.setMonth(rs.getInt("Month"));

    mte.setDay(rs.getInt("Day"));

    mte.setDatabaseSize(rs.getLong("DatabaseSize"));

    mte.setDatabaseBandwidth_Ingress(rs.getLong("DatabaseBandwidth_Ingress"));

    mte.setDatabaseBandwidth_Egress(rs.getLong("DatabaseBandwidth_Egress"));

    mte.setWebAppBandwithUse_SC(rs.getLong("WebAppBandwithUse_SC"));

    mte.setWebAppBandwithUse_CS(rs.getLong("WebAppBandwithUse_CS"));

    mte.setWebAppRequests(rs.getLong("WebAppRequests"));

    mte.setBlobStoreUsage(rs.getLong("BlobStoreUsage"));

    return mte;//w w  w  .  ja  v a  2s  .  c  o  m
}

From source file:id.go.kemenkeu.djpk.usermanagement.service.impl.PemdaServiceTest.java

@Test
public void testInsertBanyak() throws Exception {
    Tprov prov = new Tprov();
    prov.setId(99);/*from  ww  w.j a va 2  s . c  om*/

    //Simpan banyak
    List<Object> daftarPemda = new ArrayList<Object>();
    Pemda p = new Pemda();
    p.setKode("P-001");
    p.setKodeSatuanKerja("ABC0");
    p.setUraian("Pemda Tester");
    p.setUraianSingkat("Tester");
    p.setProvinsi(prov);
    daftarPemda.add(p);

    Pemda p1 = new Pemda();
    p1.setKode("P-002");
    p1.setKodeSatuanKerja("ABC1");
    p1.setUraian("Pemda Tester");
    p1.setUraianSingkat("Tester");
    p1.setProvinsi(prov);
    daftarPemda.add(p1);

    Pemda p2 = new Pemda();
    p2.setKode("P-003");
    p2.setKodeSatuanKerja("ABC2");
    p2.setUraian("Pemda Tester");
    p2.setUraianSingkat("Tester");
    p2.setProvinsi(prov);
    daftarPemda.add(p2);

    ums.simpanBanyak(daftarPemda);

    String sqlCek = "select count(*) from tpemda";
    Connection conn = dataSource.getConnection();

    ResultSet rs = conn.createStatement().executeQuery(sqlCek);
    Assert.assertTrue(rs.next());

    Long count = rs.getLong(1);
    Assert.assertEquals(new Long(4), count);

    rs.close();
    conn.close();
}

From source file:com.l2jfree.gameserver.model.entity.GrandBossState.java

public void load() {
    Connection con = null;/*  w  ww  . j  a v a2 s. c  o  m*/

    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);

        PreparedStatement statement = con
                .prepareStatement("SELECT * FROM grandboss_intervallist WHERE bossId = ?");
        statement.setInt(1, _bossId);
        ResultSet rset = statement.executeQuery();

        while (rset.next()) {
            _respawnDate = rset.getLong("respawnDate");

            if (_respawnDate - System.currentTimeMillis() <= 0) {
                _state = StateEnum.NOTSPAWN;
            } else {
                int tempState = rset.getInt("state");
                if (tempState == StateEnum.NOTSPAWN.ordinal())
                    _state = StateEnum.NOTSPAWN;
                else if (tempState == StateEnum.INTERVAL.ordinal())
                    _state = StateEnum.INTERVAL;
                else if (tempState == StateEnum.ALIVE.ordinal())
                    _state = StateEnum.ALIVE;
                else if (tempState == StateEnum.DEAD.ordinal())
                    _state = StateEnum.DEAD;
                else
                    _state = StateEnum.NOTSPAWN;
            }
        }
        rset.close();
        statement.close();
    } catch (Exception e) {
        _log.error(e.getMessage(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:org.copperengine.spring.audit.AuditTrailQueryEngine.java

@Override
public List<AuditTrailInfo> getAuditTrails(String transactionId, String conversationId, String correlationId,
        Integer level, int maxResult) {

    SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();

    String sortClause = "SEQ_ID";
    String whereClause = "where 1=1 ";
    List<Object> args = new ArrayList<Object>();

    if (level != null) {
        whereClause += " and LOGLEVEL <= ? ";
        sortClause = "LOGLEVEL";
        args.add(level);//  w ww  . ja  v  a 2 s.c  o m
    }
    if (StringUtils.hasText(correlationId)) {
        whereClause += " and CORRELATION_ID = ? ";
        sortClause = "CORRELATION_ID";
        args.add(correlationId);
    }

    if (StringUtils.hasText(conversationId)) {
        whereClause += " and CONVERSATION_ID = ? ";
        sortClause = "CONVERSATION_ID";
        args.add(conversationId);
    }

    if (StringUtils.hasText(transactionId)) {
        whereClause += " and TRANSACTION_ID = ? ";
        sortClause = "TRANSACTION_ID";
        args.add(transactionId);
    }

    String selectClause = "select " + "SEQ_ID," + "TRANSACTION_ID," + "CONVERSATION_ID," + "CORRELATION_ID,"
            + "OCCURRENCE," + "LOGLEVEL," + "CONTEXT," + "INSTANCE_ID," + "MESSAGE_TYPE";

    factory.setDataSource(getDataSource());
    factory.setFromClause("from COP_AUDIT_TRAIL_EVENT ");

    factory.setSelectClause(selectClause);

    factory.setWhereClause(whereClause);
    factory.setSortKey(sortClause);

    PagingQueryProvider queryProvider = null;
    try {
        queryProvider = (PagingQueryProvider) factory.getObject();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    }

    String query = queryProvider.generateFirstPageQuery(maxResult);

    // this.getJdbcTemplate().setQueryTimeout(1000);

    long start = System.currentTimeMillis();
    RowMapper<AuditTrailInfo> rowMapper = new RowMapper<AuditTrailInfo>() {

        public AuditTrailInfo mapRow(ResultSet rs, int arg1) throws SQLException {

            return new AuditTrailInfo(rs.getLong("SEQ_ID"), rs.getString("TRANSACTION_ID"),
                    rs.getString("CONVERSATION_ID"), rs.getString("CORRELATION_ID"),
                    rs.getTimestamp("OCCURRENCE").getTime(), rs.getInt("LOGLEVEL"), rs.getString("CONTEXT"),
                    rs.getString("INSTANCE_ID"), rs.getString("MESSAGE_TYPE"));
        }

    };
    List<AuditTrailInfo> res = this.getJdbcTemplate().query(query, rowMapper, args.toArray());

    long end = System.currentTimeMillis();

    logger.info("query took: " + (end - start) + " ms : " + query);

    return res;
}

From source file:gov.nih.nci.cacisweb.dao.virtuoso.VirtuosoCommonUtilityDAO.java

/**
 * Gets the next sequence by suffixing '_SEQ' to the table name
 * /*from  ww  w . j  a v  a 2  s. c om*/
 * @param tableName
 * @return
 * @throws DAOException
 */
public long getNextSequenceBySequenceName(String sequenceName) throws DAOException {
    log.debug("getNextSequenceByTableName(String sequenceName) - start");
    long sequenceNum = 0;
    StringBuffer sequenceSQL = new StringBuffer();
    sequenceSQL.append("SELECT " + sequenceName + ".nextval from dual");
    try {
        pstmt = new LoggableStatement(cacisConnection, sequenceSQL.toString());
        log.info("SQL getNextSequenceByTableName(String sequenceName) : " + pstmt.toString());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            sequenceNum = rs.getLong("NEXTVAL");
        }
    } catch (SQLException sqle) {
        log.error(sqle.getMessage());
        sqle.printStackTrace();
        throw new DAOException(sqle.getMessage());
    }
    return sequenceNum;
}

From source file:net.mindengine.oculus.frontend.service.project.build.JdbcBuildDAO.java

@Override
public long createBuild(Build build) throws Exception {
    String sql = "insert into builds (name, description, date, project_id) values (?,?,?,?)";
    PreparedStatement ps = getConnection().prepareStatement(sql);
    ps.setString(1, build.getName());/*  w w  w . ja  va2 s .  c  o m*/
    ps.setString(2, build.getDescription());
    ps.setTimestamp(3, new Timestamp(build.getDate().getTime()));
    ps.setLong(4, build.getProjectId());

    logger.info(ps);
    ps.execute();

    ResultSet rs = ps.getGeneratedKeys();
    if (rs.next()) {
        return rs.getLong(1);
    }
    return 0;
}

From source file:metadata.etl.lineage.AzJobChecker.java

/**
 * Read the blob from "flow_data", do a topological sort on the nodes. Give them the sort id.
 * @param startTimeStamp the begin timestamp in milli seconds
 * @param endTimeStamp the end timestamp in milli seconds
 * @return//  ww w  .  j  a  va 2  s .  co m
 */
public List<AzkabanJobExecRecord> getRecentFinishedJobFromFlow(long startTimeStamp, long endTimeStamp)
        throws SQLException, IOException {

    logger.info("Get the jobs from time : {} to time : {}", startTimeStamp, endTimeStamp);
    List<AzkabanJobExecRecord> results = new ArrayList<>();
    Statement stmt = conn.createStatement();
    final String cmd = "select exec_id, flow_id, status, submit_user, flow_data from execution_flows where end_time > "
            + startTimeStamp + " and end_time < " + endTimeStamp;
    logger.info("Get recent flow sql : " + cmd);
    final ResultSet rs = stmt.executeQuery(cmd); // this sql take 3 second to execute

    while (rs.next()) {
        long execId = rs.getLong("exec_id");
        Blob flowBlob = rs.getBlob("flow_data");
        GZIPInputStream gzip = new GZIPInputStream(flowBlob.getBinaryStream());
        String flowJson = IOUtils.toString(gzip, "UTF-8");
        results.addAll(parseJson(flowJson, execId));
    }
    return results;
}

From source file:com.fileanalyzer.dao.impl.FileStatisticDAOImpl.java

@Override
public Long getMaxId() {
    Connection con = null;//from  ww  w.  j  av a  2  s .c  om
    PreparedStatement statement = null;
    String sql = "select max(id) from " + FileStatistic.FileStatisticKey.TABLE;
    Long maxId = null;
    try {
        con = DBConnector.getConnection();
        con.setAutoCommit(false);
        statement = con.prepareStatement(sql);
        ResultSet rs = statement.executeQuery();
        if (rs.next())
            maxId = rs.getLong(1);
        con.commit();
    } catch (SQLException e) {
        handleException(e, con);
    } finally {
        doFinal(con, statement);
    }
    return maxId;
}

From source file:org.jasig.schedassist.impl.owner.PersistenceScheduleOwnerRowMapper.java

public PersistenceScheduleOwner mapRow(ResultSet rs, int rowNum) throws SQLException {
    PersistenceScheduleOwner owner = new PersistenceScheduleOwner();
    owner.setCalendarUniqueId(rs.getString("external_unique_id"));
    owner.setUsername(rs.getString("username"));
    owner.setId(rs.getLong("internal_id"));
    return owner;
}