Example usage for org.springframework.jdbc.core RowMapper RowMapper

List of usage examples for org.springframework.jdbc.core RowMapper RowMapper

Introduction

In this page you can find the example usage for org.springframework.jdbc.core RowMapper RowMapper.

Prototype

RowMapper

Source Link

Usage

From source file:dao.CustomerDAO.java

public Customer authenticate(String email, String pw) {
    String Query = "SELECT UserId, SSN, Sex, EmailId, DOB, Rating\n" + "FROM user\n" + "WHERE EmailId = \""
            + email + "\" AND UserId = " + pw;
    pass = pw;/*from   w  w w.j av  a  2s. c o m*/
    Customer customer = this.jdbcTemplate.queryForObject(Query, new RowMapper<Customer>() {
        @Override
        public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
            if (rs.getString("UserId").matches(pass)) {
                cust = new Customer();
                cust.setCustomerID(rs.getInt("UserId"));
                cust.setSSN(rs.getInt("SSN"));
                String sex = rs.getString("Sex");
                cust.setSex(sex.charAt(0));
                cust.setDOB("DOB");
                cust.setRating(rs.getInt("Rating"));

                //table = person for address
                getAddress(cust.getSSN());

                //table = circlemembership for circle ids
                cust.setCircleID(getCircles(cust.getCustomerID()));
                return cust;
            } else {
                return null;
            }

        }
    });
    return customer;
}

From source file:com.javacodegags.waterflooding.model.ParametersImplemented.java

@Override
public List<Parameters> getListById(int parameterId) {
    String sql = "SELECT * " + "FROM parameters " + "INNER JOIN criteria "
            + "ON parameters.foreign_to_criteria=criteria.Id " + "Where parameters.foreign_to_criteria="
            + parameterId + ";";
    List<Parameters> listParameters = jdbcTemplate.query(sql, new RowMapper<Parameters>() {
        @Override//from w w  w . j  ava 2  s.c  o  m
        public Parameters mapRow(ResultSet rs, int rowNum) throws SQLException {
            Parameters parameters = new Parameters();
            parameters.setId(rs.getInt("id"));
            parameters.setName(rs.getString("name"));
            parameters.setValue(rs.getFloat("value"));
            parameters.setForeignId(rs.getInt("foreign_to_criteria"));
            return parameters;
        }
    });
    return listParameters;
}

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

@Override
public List<Category> getALL() throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_category";

    return jdbcTemplate.query(sql, new RowMapper<Category>() {

        @Override/* w w w .  ja  v a2  s.c  o m*/
        public Category mapRow(ResultSet rs, int i) throws SQLException {
            Category c = new Category();
            c.setId(rs.getInt("category_id"));
            c.setCategoryName(rs.getString("category_name"));

            return c;
        }
    });
}

From source file:com.leapfrog.project.DAO.Impl.ProductDAOImpl.java

@Override
public List<Product> getAll() throws SQLException, ClassNotFoundException {

    String sql = "SELECT * FROM product";

    return jdbcTemplate.query(sql, new RowMapper<Product>() {

        @Override/*ww w.  java  2  s  .  c  om*/
        public Product mapRow(ResultSet rs, int i) throws SQLException {

            Product pro = new Product();
            pro.setId(rs.getInt("id"));
            pro.setName(rs.getString("name"));
            pro.setDescription(rs.getString("description"));
            pro.setCostPrice(rs.getInt("costPrice"));
            pro.setSellingPrice(rs.getInt("sellingPrice"));

            return pro;
        }
    });
}

From source file:com.javacodegags.waterflooding.model.CaptionImplemented.java

@Override
public List<Caption> list() {
    String sql = "SELECT * FROM caption";
    List<Caption> listCaption = jdbcTemplate.query(sql, new RowMapper<Caption>() {
        @Override//from ww  w .ja v a  2s  .  co m
        public Caption mapRow(ResultSet rs, int rowNum) throws SQLException {
            Caption caption = new Caption();
            caption.setId(rs.getInt("id"));
            caption.setName(rs.getString("name"));
            return caption;
        }
    });
    return listCaption;
}

From source file:com.company.dao.impl.StudentDAOImpl.java

@Override
public Student getById(int id) throws SQLException {
    return jdbcTemplate.queryForObject(SQLConstant.STUDENT_GETBYID, new Object[] { id },
            new RowMapper<Student>() {

                @Override//from  www.  j  a  v  a2  s .c o m
                public Student mapRow(ResultSet rs, int i) throws SQLException {
                    return mapData(rs);
                }
            });
}

From source file:model.DbTable.java

@Override
public boolean authenticate(String username, String password) {

    boolean status = false;
    String encrypassword = Encrypt.getMD5(password);
    String SQL = "SELECT count(*) as user FROM `login` WHERE username=? AND password=?";
    try {/*w ww.  j a va2  s.  c om*/
        status = (boolean) jdbcTemplateObject.queryForObject(SQL, new Object[] { username, encrypassword },
                new RowMapper() {

                    @Override
                    public Object mapRow(ResultSet rs, int i) throws SQLException {
                        int login_status = rs.getInt("user");
                        if (login_status == 1) {
                            return true;
                        } else {
                            return false;
                        }
                    }

                });
        return status;
    } catch (EmptyResultDataAccessException e) {
        status = false;
        return status;
    }
}

From source file:com.ewcms.content.particular.dao.FontArticleMainDAO.java

public List<ArticleMainVO> findArticleMainByChannelId(int channelId) {
    String sql = "Select t2.title,t2.url " + "From content_article_main t1,content_article t2 "
            + "where t1.article_id=t2.id and t1.channel_id=? " + "order by t2.id";
    Object[] params = new Object[] { channelId };
    List<ArticleMainVO> list = jdbcTemplate.query(sql, params, new RowMapper<ArticleMainVO>() {
        @Override/*from  ww w  .  j a va2s .  c om*/
        public ArticleMainVO mapRow(ResultSet rs, int rowNum) throws SQLException {
            return articleRowMapper(rs);
        }
    });
    return list;
}

From source file:dao.BankDao.java

public Bank getBankForCode(String code) {

    logger.info("run");

    SqlParameterSource parameterSource = new MapSqlParameterSource("code", code);
    Bank bank;/*from  w  w  w .j  a va  2 s.c o m*/
    try {

        bank = jdbc.queryForObject("SELECT * FROM banktable WHERE code = :code", parameterSource,
                new RowMapper<Bank>() {

                    @Override
                    public Bank mapRow(ResultSet rs, int rowNum) throws SQLException {
                        return readOneBank(rs);
                    }
                });
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
    return bank;
}

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

@Override
public List<Supplier> getALL() throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_supplier";

    return jdbcTemplate.query(sql, new RowMapper<Supplier>() {

        @Override//from www.j av  a2 s.  c o m
        public Supplier mapRow(ResultSet rs, int i) throws SQLException {
            Supplier s = new Supplier();
            s.setId(rs.getInt("supplier_id"));
            s.setSupplierName(rs.getString("supplier_name"));
            s.setAddress(rs.getString("address"));
            s.setContact(rs.getString("contact"));
            s.setEmail(rs.getString("email"));
            s.setAddedDate(rs.getDate("added_date"));
            s.setStatus(rs.getBoolean("status"));

            return s;
        }
    });
}