Example usage for org.springframework.jdbc.support.rowset SqlRowSet getInt

List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet getInt

Introduction

In this page you can find the example usage for org.springframework.jdbc.support.rowset SqlRowSet getInt.

Prototype

int getInt(String columnLabel) throws InvalidResultSetAccessException;

Source Link

Document

Retrieve the value of the indicated column in the current row as an int.

Usage

From source file:edu.uca.aca2016.impulse.repository.InteractionsDAO.java

/**
 *getClientsMap method and SQL Query//w w  w. j a  v  a2s .  c  o  m
 * @return
 */
public Map<Integer, String> getClientsMap() {
    Map<Integer, String> clients = new LinkedHashMap<>();
    String sql = "SELECT ClientID, FirstName, LastName FROM Client ORDER BY FirstName";

    SqlRowSet rs = template.queryForRowSet(sql);

    while (rs.next()) {
        clients.put(rs.getInt(1), rs.getString(2) + " " + rs.getString(3));
    }

    return clients;
}

From source file:repository.EventLogDAO.java

/**
 * Gets a count of the events in the Event Log, mainly for pagination
 * @return/*  w w  w .j  av a  2s .  com*/
 */
public int getEventsCount() {
    String sql = "SELECT COUNT(EventID) AS rowcount FROM interactions";
    SqlRowSet rs = template.queryForRowSet(sql);

    if (rs.next()) {
        return rs.getInt("rowcount");
    }

    return 1;
}

From source file:dk.nsi.sdm4.dosering.parser.DoseringParserIntegrationTest.java

@Test
public void Should_import_dosage_units_correctly() throws Exception {
    runImporter();//from   ww w. j a  v  a2 s  .c  o  m

    SqlRowSet rs = jdbcTemplate.queryForRowSet("select * from DosageUnit");
    rs.next();

    assertThat(rs.getLong("releaseNumber"), equalTo(125L));
    assertThat(rs.getInt("code"), equalTo(8));
    assertThat(rs.getString("textSingular"), equalTo("brusetablet"));
    assertThat(rs.getString("textPlural"), equalTo("brusetabletter"));

    // expect only one row
    assertFalse(rs.next());

}

From source file:repository.EventLogDAO.java

/**
 * Gets a map of Users, mainly for adding and editing events
 * @return/*from  w  w  w . j  a va2  s . c o  m*/
 */
public Map<Integer, String> getUsersMap() {
    Map<Integer, String> users = new LinkedHashMap<Integer, String>();
    String sql = "SELECT UserID,Username FROM users";

    SqlRowSet srs = template.queryForRowSet(sql);

    while (srs.next()) {
        users.put(srs.getInt(1), srs.getString(2));
    }
    return users;
}

From source file:repository.EventLogDAO.java

/**
 * Gets a map of Clients, mainly for adding and editing events
 * @return/*from   w  w w. j  a  v  a  2 s . c  om*/
 */
public Map<Integer, String> getClientsMap() {
    Map<Integer, String> clients = new LinkedHashMap<Integer, String>();
    String sql = "SELECT ClientID,First_Name,Last_Name FROM clients";

    SqlRowSet srs = template.queryForRowSet(sql);

    while (srs.next()) {
        clients.put(srs.getInt("ClientID"), srs.getString("First_Name") + " " + srs.getString("Last_Name"));
    }
    return clients;
}

From source file:ru.org.linux.poll.PollDao.java

/**
 *  ?  .//from ww w  .  j a v a2s.  c o  m
 *
 * @param pollId  ??
 * @return  ?
 * @throws PollNotFoundException ? ?  ??
 */
public Poll getPoll(final int pollId) throws PollNotFoundException {
    int currentPollId = getCurrentPollId();

    SqlRowSet rs = jdbcTemplate.queryForRowSet(queryPool, pollId);

    if (!rs.next()) {
        throw new PollNotFoundException();
    }

    return new Poll(pollId, rs.getInt("topic"), rs.getBoolean("multiselect"), pollId == currentPollId,
            getVoteDTO(pollId));
}

From source file:ru.org.linux.group.TopicsListItem.java

public TopicsListItem(User author, SqlRowSet rs, int messagesInPage, ImmutableList<String> tags) {
    this.author = author;
    this.tags = tags;
    subj = StringUtil.makeTitle(rs.getString("subj"));

    Timestamp lastmod = rs.getTimestamp("lastmod");
    if (lastmod == null) {
        this.lastmod = new Timestamp(0);
    } else {/* w w  w .j  a  va  2 s.  c  om*/
        this.lastmod = lastmod;
    }

    msgid = rs.getInt("msgid");
    deleted = rs.getBoolean("deleted");
    stat1 = rs.getInt("stat1");
    stat3 = rs.getInt("stat3");
    stat4 = rs.getInt("stat4");
    sticky = rs.getBoolean("sticky");
    resolved = rs.getBoolean("resolved");

    pages = Topic.getPageCount(stat1, messagesInPage);
}

From source file:com.emergya.openfleetservices.importer.ddbb.JDBCConnector.java

/**
 * Given a tablename and the column where the address lies, for each row, it
 * geocodes the address and saves the geometry on the geocolumn
 * /*www  .  j  av  a2  s  . c  o  m*/
 * @param dsd
 * @return
 */
public int geocode(DataSetDescriptor dsd, String address) {
    NominatimConnector nm = new NominatimConnector("http://nominatim.openstreetmap.org/search.php");
    nm.setFormat("json");
    boolean containColumn = address.contains("{");
    int rowCont = 0;
    if (!containColumn) {
        // In order to not contain a column name into the search, the geometry field is the same for all
        nm.setQuery(address);
        String geoColumnAddress = nm.getAddress();
        System.out.println(geoColumnAddress);
        // Update all fields with geoColumnAddress and geoColumnName
        this.updateGeometryColumn(dsd, geoColumnAddress);
    } else {
        // Get the columns from address
        List<String> col = new LinkedList<String>();
        nm.getColumnsToGeom(col, address);
        SqlRowSet columnsMap = this.getColumnsByList(dsd, col);
        while (columnsMap.next()) {
            for (String c : col) {
                String dir = address;
                String param = columnsMap.getString(c);
                int pk = columnsMap.getInt(dsd.getNamePK());
                dir = dir.replace("{" + c + "}", param);
                nm.setQuery(dir);
                String geoAddress = nm.getAddress();
                if (geoAddress != null) {
                    String[] splitGeom = geoAddress.split(",");
                    Double lon = Double.valueOf(splitGeom[0]);
                    Double lat = Double.valueOf(splitGeom[1]);
                    String updateSQL = "UPDATE " + dsd.getTablename() + " SET " + dsd.getGeoColumnName()
                            + " = ST_GeomFromEWKT(:geom)" + " WHERE " + dsd.getNamePK() + "=:pk";
                    Map<String, Object> paramMap = new HashMap<String, Object>();
                    paramMap.put("pk", pk);
                    paramMap.put("geom", "SRID=4326;POINT(" + lon + " " + lat + ")");
                    this.namedJdbcTemplate.update(updateSQL, paramMap);
                } else {
                    rowCont++;
                }
            }
        }
    }
    return rowCont;
}