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:AllEmployeesServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>All Employees</title></head>");
    out.println("<body>");
    out.println("<center><h1>All Employees</h1>");
    Connection conn = null;//from w  w  w  . j  ava 2 s.  c om
    Statement stmt = null;
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        conn = DriverManager.getConnection("jdbc:odbc:Employees");
        stmt = conn.createStatement();
        String orderBy = request.getParameter("sort");
        if ((orderBy == null) || orderBy.equals("")) {
            orderBy = "SSN";
        }
        String orderByDir = request.getParameter("sortdir");
        if ((orderByDir == null) || orderByDir.equals("")) {
            orderByDir = "asc";
        }
        String query = "SELECT Employees.SSN, Employees.Name, " + "Employees.Salary, "
                + "Employees.Hiredate, Location.Location " + "FROM Location " + "INNER JOIN Employees "
                + "ON Location.Loc_Id = Employees.Loc_Id " + "ORDER BY " + orderBy + " " + orderByDir + ";";
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            long employeeSSN = rs.getLong("SSN");
            String employeeName = rs.getString("Name");
            long employeeSalary = rs.getLong("Salary");
            Date employeeHiredate = rs.getDate("Hiredate");
            String employeeLocation = rs.getString("Location");
            out.print(employeeSSN + "::");
            out.print(employeeName + "::");
            out.print(employeeSalary + "::");
            out.print(employeeHiredate + "::");
            out.print(employeeLocation + "::");
        }
    } catch (SQLException e) {
        out.println("An error occured while retrieving " + "all employees: " + e.toString());
    } catch (ClassNotFoundException e) {
        throw (new ServletException(e.toString()));
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException ex) {
        }
    }
    out.println("</center>");
    out.println("</body>");
    out.println("</html>");
    out.close();
}

From source file:com.grayfox.server.dao.jdbc.CredentialJdbcDao.java

@Override
public Credential findByFoursquareAccessToken(String foursquareAccessToken) {
    List<Credential> credentials = getJdbcTemplate().query(getQuery("Credential.findByFoursquareAccessToken"),
            (ResultSet rs, int i) -> {
                Credential credential = new Credential();
                int columnIndex = 1;
                credential.setId(rs.getLong(columnIndex++));
                credential.setAccessToken(rs.getString(columnIndex++));
                credential.setFoursquareAccessToken(foursquareAccessToken);
                return credential;
            }, foursquareAccessToken);//from   www  .jav a  2 s.  co  m
    if (credentials.size() > 1) {
        throw new DaoException.Builder().messageKey("data.integrity.error").build();
    }
    return credentials.isEmpty() ? null : credentials.get(0);
}

From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java

protected Long getLong(final ResultSet rs, final String columnLabel) throws SQLException {
    long result = rs.getLong(columnLabel);
    return rs.wasNull() ? null : result;
}

From source file:architecture.ee.web.community.timeline.dao.jdbc.JdbcTimelineDao.java

public List<Long> getTimelineIds(int objectType, long objectId) {
    return getExtendedJdbcTemplate().query(getBoundSql(
            "ARCHITECTURE_COMMUNITY.SELECT_TIMELINE_IDS_BY_OBJECT_TYPE_AND_OBJECT_ID_WITH_DATE_DESC").getSql(),
            new RowMapper<Long>() {
                public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return rs.getLong(1);
                }/*w w w .ja va  2s  .  c  o m*/
            }, new SqlParameterValue(Types.NUMERIC, objectType),
            new SqlParameterValue(Types.NUMERIC, objectId));
}

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

@Override
public Iterable<Long> loadAllKeys() {
    return new CloseableIterable<Long>() {
        @Override//from  ww  w. java  2s . co  m
        protected CloseableIterator<Long> closeableIterator() {
            return tpl.queryForIter("SELECT id FROM kfka", Collections.emptyMap(), new RowMapper<Long>() {
                @Override
                public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return rs.getLong("id");
                }
            });
        }
    };
}

From source file:com.splicemachine.derby.utils.TimestampAdminIT.java

/**
 * Tests SYSCS_GET_TIMESTAMP_GENERATOR_INFO system procedure.
 *//*from  w w w . j a v a 2s .  c  om*/
@Test
public void testGetTimestampGeneratorInfo() throws Exception {
    String template = "call SYSCS_UTIL.SYSCS_GET_TIMESTAMP_GENERATOR_INFO()";
    CallableStatement cs = methodWatcher.prepareCall(template);
    ResultSet rs = cs.executeQuery();
    int rowCount = 0;
    while (rs.next()) {
        rowCount++;
        long num = rs.getLong(1);
        Assert.assertTrue("Unexpected number of timestamps", num > 0);
    }
    Assert.assertTrue(rowCount == 1);
    DbUtils.closeQuietly(rs);
}

From source file:com.splicemachine.derby.utils.TimestampAdminIT.java

/**
 * Tests SYSCS_GET_TIMESTAMP_REQUEST_INFO system procedure.
 *//*  www .j  a  v  a2s . co m*/
@Test
public void testGetTimestampRequestInfo() throws Exception {
    String template = "call SYSCS_UTIL.SYSCS_GET_TIMESTAMP_REQUEST_INFO()";
    CallableStatement cs = methodWatcher.prepareCall(template);
    ResultSet rs = cs.executeQuery();
    int rowCount = 0;
    while (rs.next()) {
        rowCount++;
        long num = rs.getLong(2);
        Assert.assertTrue("Unexpected number of requests", num > 0);
    }
    Assert.assertTrue(rowCount > 0);
    DbUtils.closeQuietly(rs);
}

From source file:mum.bigdata.car.recommender.repository.impl.ModelRepositoryImpl.java

@Override
public List<Model> buildResult(ResultSet rs) throws SQLException {
    List<Model> models = new ArrayList<>();
    while (rs.next()) {
        Model model = new Model();
        model.setId(rs.getLong("model.id"));
        model.setName(rs.getString("model.model"));
        models.add(model);/*from  w w  w. j  a  v  a2  s.c o  m*/
    }
    return models;
}

From source file:org.cleverbus.core.common.asynch.RepairProcessingMsgServiceDbTest.java

@Test
public void testRepairProcessingMessages() {
    msg.setState(MsgStateEnum.PROCESSING);
    msg.setStartProcessTimestamp(msg.getMsgTimestamp());
    messageDao.insert(msg);/*from  w  w  w . j  av a2 s  .co  m*/

    em.flush();

    int msgCount = JdbcTestUtils.countRowsInTable(getJdbcTemplate(), "message");
    assertThat(msgCount, is(1));

    // call repairing
    repairMsgService.repairProcessingMessages();

    em.flush();

    // verify results
    msgCount = JdbcTestUtils.countRowsInTable(getJdbcTemplate(), "message");
    assertThat(msgCount, is(1));

    getJdbcTemplate().query("select * from message", new RowMapper<Message>() {
        @Override
        public Message mapRow(ResultSet rs, int rowNum) throws SQLException {
            // verify row values
            assertThat(rs.getLong("msg_id"), is(1L));
            assertThat((int) rs.getShort("failed_count"), is(1));
            assertThat(rs.getTimestamp("last_update_timestamp"), notNullValue());
            assertThat(MsgStateEnum.valueOf(rs.getString("state")), is(MsgStateEnum.PARTLY_FAILED));

            return new Message();
        }
    });
}

From source file:io.apiman.manager.api.jdbc.handlers.UsagePerPlanHandler.java

/**
 * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
 *///from  www  .ja  v a2s.c om
@Override
public UsagePerPlanBean handle(ResultSet rs) throws SQLException {
    UsagePerPlanBean rval = new UsagePerPlanBean();
    while (rs.next()) {
        String planId = rs.getString(1);
        long count = rs.getLong(2);
        if (planId != null) {
            rval.getData().put(planId, count);
        }
    }
    return rval;
}