Example usage for java.sql ResultSet getInt

List of usage examples for java.sql ResultSet getInt

Introduction

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

Prototype

int getInt(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

From source file:scriptella.driver.spring.SpringDriverTest.java

public void test() throws SQLException, ClassNotFoundException, EtlExecutorException {
    BeanFactory bf = new ClassPathXmlApplicationContext("scriptella/driver/spring/springbeans.xml");
    DataSource ds = (DataSource) bf.getBean("datasource"); //Test if bean factory contain correct data
    Connection con = ds.getConnection();
    con.createStatement().executeQuery("select * from AutoStart"); //A table should be created on startup
    EtlExecutor exec = (EtlExecutor) bf.getBean("executor");
    exec.execute();//from w ww  . j  a va2s. c  o  m
    con.createStatement().executeQuery("select * from SpringTable"); //A table should be created
    //Test batched executor
    ResultSet rs = con.createStatement().executeQuery("select * from Batch order by id");//A table should be created
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertFalse(rs.next());
    con.createStatement().execute("SHUTDOWN");
}

From source file:Phnbk.java

private void detailsNumber(Statement statement, String param, Connection connection) throws Exception {
    String tempo2 = "SELECT m.id, m.number FROM mobile_number AS m INNER JOIN home_number AS h ON m.id = h.id "
            + "INNER JOIN work_number AS w ON w.id = m.id " + "WHERE m.number = '" + param + "' OR w.number = '"
            + param + "' " + "OR h.number = '" + param + "'";
    ResultSet res = statement.executeQuery(tempo2);
    res.next();/*ww  w.  j  a va 2 s .c om*/
    int id = res.getInt("id");

    String tempo = "SELECT * FROM phone_book WHERE id = '" + id + "'";
    ResultSet result = statement.executeQuery(tempo);

    while (result.next()) {
        printOutDetails(result);

        Statement statement2 = connection.createStatement();
        for (String s : names) {
            tempo = "SELECT number FROM " + s + "_number WHERE id = '" + id + "'";
            ResultSet result2 = statement2.executeQuery(tempo);
            System.out.print(s + " : ");
            printOutNumber(result2);
        }
    }

}

From source file:org.cateproject.features.rowmapper.FeatureRowMapper.java

/** {@inheritDoc} */
@Override//ww w.j a  v  a  2  s  .  c o m
public Feature mapRow(ResultSet rs, int rowNum) throws SQLException {
    String featUid = rs.getString(COL_FEAT_UID);
    Feature f = new Feature(featUid, rs.getInt(COL_FEAT_ENABLE) > 0);
    f.setDescription(rs.getString(COL_FEAT_DESCRIPTION));
    f.setGroup(rs.getString(COL_FEAT_GROUPNAME));

    // Build Flipping Strategy From DataBase
    String strategy = rs.getString(COL_FEAT_STRATEGY);
    if (strategy != null && !"".equals(strategy)) {
        try {
            FlippingStrategy flipStrategy = (FlippingStrategy) Class.forName(strategy).newInstance();
            flipStrategy.init(featUid, ParameterUtils.toMap(rs.getString(COL_FEAT_EXPRESSION)));
            f.setFlippingStrategy(flipStrategy);
        } catch (InstantiationException ie) {
            throw new FeatureAccessException("Cannot instantiate Strategy, no default constructor available",
                    ie);
        } catch (IllegalAccessException iae) {
            throw new FeatureAccessException("Cannot instantiate Strategy, no visible constructor", iae);
        } catch (ClassNotFoundException e) {
            throw new FeatureAccessException("Cannot instantiate Strategy, classNotFound", e);
        }
    }
    return f;
}

From source file:springmvc.repository.mappers.HighscoreMapper.java

public HighscoreDisplay mapRow(ResultSet rs, int i) throws SQLException {
    HighscoreDisplay e = new HighscoreDisplay();
    e.setFname(rs.getString("fname"));
    e.setLname(rs.getString("lname"));
    e.setScore(rs.getInt("score"));
    return e;/*from  w w  w . j a  va2 s  .c o m*/
}

From source file:tianci.pinao.dts.dao.impl.ConfigDaoImpl.java

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

    license.setId(rs.getInt("id"));
    license.setMac(rs.getString("mac"));
    license.setUseTime(rs.getLong("use_time"));
    Timestamp ts = rs.getTimestamp("lastmod_time");
    if (ts != null)
        license.setLastModTime(new Date(ts.getTime()));
    license.setLastModUserid(rs.getInt("lastmod_userid"));

    return license;
}

From source file:net.mms_projects.copy_it.api.http.pages.v1.UserProfile.java

public FullHttpResponse onGetRequest(HttpRequest request, Database database, HeaderVerifier headerVerifier)
        throws Exception {
    PreparedStatement statement = database.getConnection().prepareStatement(SELECT_USER);
    statement.setInt(1, headerVerifier.getUserId());
    ResultSet result = statement.executeQuery();
    if (result.first()) {
        final JSONObject json = new JSONObject();
        json.put(ID, result.getInt(ID));
        json.put(EMAIL, result.getString(EMAIL));
        json.put(SIGNED_UP, result.getInt(SIGNED_UP));
        result.close();/*  www  . ja  v  a 2s  . c o m*/
        return new DefaultFullHttpResponse(request.getProtocolVersion(), OK,
                Unpooled.copiedBuffer(json.toString(), CharsetUtil.UTF_8));
    }
    result.close();
    return null;
}

From source file:com.epam.repository.book.BookRepository.java

public Book find(final Integer id) {
    return jdbcTemplate.queryForObject(FIND_BOOK_BY_ID, new Object[] { id }, new RowMapper<Book>() {
        public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
            Book book = new Book();
            int authorID = rs.getInt("Author");
            int genreID = rs.getInt("Genre");
            book.setId(id);//from w  ww.j a v  a  2s  . c  om
            book.setGenre(new Genre(genreID, null));
            book.setStock(rs.getInt("Stock"));
            book.setAuthor(new Author(authorID, null, null));
            book.setTitle(rs.getString("Title"));
            return book;
        }
    });
}

From source file:com.epam.repository.book.BookRepository.java

public Book findByTitle(final String title) {
    return jdbcTemplate.queryForObject(FIND_BOOKS_BY_TITLE, new Object[] { title }, new RowMapper<Book>() {
        public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
            Book book = new Book();
            int authorID = rs.getInt("Author");
            int genreID = rs.getInt("Genre");
            book.setId(rs.getInt("ID"));
            book.setGenre(new Genre(genreID, null));
            book.setStock(rs.getInt("Stock"));
            book.setAuthor(new Author(authorID, null, null));
            book.setTitle(title);/*  w  w w  . ja  v a2s.  com*/
            return book;
        }
    });
}

From source file:com.epam.repository.book.BookRepository.java

public List<Book> findAll() {
    List<Book> books = jdbcTemplate.query(GET_ALL_BOOKS, new RowMapper<Book>() {
        public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
            Book book = new Book();
            int authorID = rs.getInt("Author");
            int genreID = rs.getInt("Genre");
            book.setId(rs.getInt("ID"));
            book.setGenre(new Genre(genreID, null));
            book.setStock(rs.getInt("Stock"));
            book.setAuthor(new Author(authorID, null, null));
            book.setTitle(rs.getString("Title"));
            return book;
        }//from  w ww.j  av a 2s  . c o  m
    });
    return books;
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.ProductDAOImpl.java

@Override
public Product getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_product WHERE product_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Product>() {

        @Override//from  ww w  .j a  va2s . c om
        public Product mapRow(ResultSet rs, int i) throws SQLException {
            Product p = new Product();
            p.setId(rs.getInt("product_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setSellingPrice(rs.getInt("selling_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setCategoryName(rs.getString("category_name"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setAddedDate(rs.getDate("added_date"));
            p.setModifiedDate(rs.getDate("modified_date"));
            p.setStatus(rs.getBoolean("status"));
            return p;
        }
    });
}