List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:dao.BankDao.java
public List<Bank> getBankForName(String name) { logger.info("run"); SqlParameterSource parameterSource = new MapSqlParameterSource("name", "%" + name.toUpperCase() + "%"); return jdbc.query("SELECT * FROM banktable WHERE name LIKE :name", parameterSource, new RowMapper<Bank>() { @Override//w w w. jav a 2s .com public Bank mapRow(ResultSet rs, int rowNum) throws SQLException { return readOneBank(rs); } }); }
From source file:org.ambraproject.doi.JdbcResolverService.java
@Override public AnnotationInfo getAnnotationInfo(String doi) { log.debug("looking up doi {} in Annotation table", doi); try {/* w w w. jav a 2 s. c om*/ return (AnnotationInfo) jdbcTemplate.query("select an.annotationID, a.doi, an.type from annotation an " + " inner join article a on an.articleID = a.articleID " + " where an.annotationURI = ?", new Object[] { doi }, new RowMapper() { @Override public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return new AnnotationInfo(rs.getLong(1), //annotationId rs.getString(2), //article doi rs.getString(3) //type ); } }).get(0); } catch (IndexOutOfBoundsException e) { //no annotation return null; } }
From source file:com.mesut.daopattern.OffersDAO.java
public Offer findById(int id) { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("id", id); return jdbc.queryForObject("select * from offers where id= :id", params, new RowMapper<Offer>() { public Offer mapRow(ResultSet rs, int i) throws SQLException { Offer offer = new Offer(); offer.setId(rs.getInt("id")); offer.setName(rs.getString("name")); offer.setEmail(rs.getString("email")); offer.setText(rs.getString("text")); return offer; }/*from w w w.jav a2 s . c om*/ }); }
From source file:com.onclave.testbench.jdbcTemplate.DAOSupport.StudentDAOImplementation.java
@Override public List<StudentPOJO> queryAllStudents() { List<StudentPOJO> students = this.jdbcTemplate.query(QueryStatements.QUERY_ALL_STUDENTS_SQL, new RowMapper<StudentPOJO>() { @Override/*from ww w. ja va 2 s . c o m*/ public StudentPOJO mapRow(ResultSet resultSet, int rowNum) throws SQLException { StudentPOJO student = new StudentPOJO(); student.setIdStudent(resultSet.getLong("IDStudents")); student.setName(resultSet.getString("studentName")); student.setRollNo(resultSet.getString("studentRollNo")); student.setEmail(resultSet.getString("studentEmail")); student.setActive(resultSet.getBoolean("studentActive")); student.setAge(resultSet.getInt("studentAge")); return student; } }); return students; }
From source file:com.kdubb.socialshowcaseboot.account.JdbcAccountRepository.java
public Account findAccountByUsername(String username) { return jdbcTemplate.queryForObject("select username, firstName, lastName from Account where username = ?", new RowMapper<Account>() { public Account mapRow(ResultSet rs, int rowNum) throws SQLException { return new Account(rs.getString("username"), null, rs.getString("firstName"), rs.getString("lastName")); }/*from www . j a v a 2 s .co m*/ }, username); }
From source file:com.stehno.sjdbcx.reflection.extractor.RowMapperExtractor.java
public RowMapper extract(final Method method) { final com.stehno.sjdbcx.annotation.RowMapper mapper = AnnotationUtils.getAnnotation(method, com.stehno.sjdbcx.annotation.RowMapper.class); if (mapper == null) { Class mappedType = method.getReturnType(); if (Collection.class.isAssignableFrom(mappedType)) { mappedType = (Class) ((ParameterizedType) method.getGenericReturnType()) .getActualTypeArguments()[0]; } else if (mappedType.isArray()) { throw new UnsupportedOperationException("Auto-mapping for array return types is not yet supported"); } else if (mappedType.isPrimitive()) { if (mappedType == int.class || mappedType == long.class) { return new SingleColumnRowMapper(); } else if (mappedType == boolean.class) { return new RowMapper<Boolean>() { @Override//from w w w. j a v a2 s .com public Boolean mapRow(final ResultSet resultSet, final int i) throws SQLException { return resultSet.getBoolean(1); } }; } } return new BeanPropertyRowMapper(mappedType); } else { final String extractKey = mapper.value(); if (StringUtils.isEmpty(extractKey)) { return resolve((Class<RowMapper>) mapper.type()); } else { return resolve(extractKey); } } }
From source file:model.DbTable.java
public List<product> getProduct() { List<product> list = new ArrayList<product>(); list = jdbcTemplateObject.query("SELECT * FROM `product`", new RowMapper<product>() { @Override/*from w w w. j a v a 2 s . c o m*/ public product mapRow(ResultSet rs, int rowNum) throws SQLException { product p = new product(); p.setId(rs.getInt("id")); p.setProduct_name(rs.getString("product_name")); p.setProduct_type(rs.getString("product_type")); System.out.print("run list "); return p; } }); return list; }
From source file:com.ccinepal.springjdbc.daoimpl.StudentDAOImpl.java
@Override public List<Student> getAll() throws SQLException { String sql = "Select *from student"; return jdbcTemplate.query(sql, new RowMapper<Student>() { @Override/*from w ww .j a v a 2s. com*/ public Student mapRow(ResultSet rs, int i) throws SQLException { Student s = new Student(); s.setId(rs.getInt("student_id")); s.setName(rs.getString("name")); return s; } }); }
From source file:com.havoc.hotel.admin.dao.impl.BookingDAOImpl.java
@Override public List<Booking> getALL() throws SQLException { return jdbcTemplate.query(SQLConstant.BOOKING_GETALL, new RowMapper<Booking>() { @Override//from w w w . j a v a2 s .c o m public Booking mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }
From source file:com.ewcms.content.particular.dao.FontArticleMainDAO.java
public List<ChannelVO> findChannelChildrensByChannelId(int channelId) { String sql = "Select t1.id " + "From site_channel t1 " + "where t1.parent_id=? " + "order by t1.id"; Object[] params = new Object[] { channelId }; List<ChannelVO> list = jdbcTemplate.query(sql, params, new RowMapper<ChannelVO>() { @Override/*from ww w .j a v a 2 s. com*/ public ChannelVO mapRow(ResultSet rs, int rowNum) throws SQLException { return channelRowMapper(rs); } }); return list; }