List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.ccinepal.springjdbc.daoimpl.StudentDAOImpl.java
@Override public Student getById(int id) throws SQLException { String sql = "select *from student where student_id=? "; return jdbcTemplate.queryForObject(sql, new RowMapper<Student>() { @Override//from w w w .j a va 2 s . c om 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; } }, new Object[] { id }); }
From source file:ru.org.linux.user.ProfileDao.java
@Nonnull public Profile readProfile(@NotNull User user) { List<Profile> profiles = jdbcTemplate.query("SELECT settings, main FROM user_settings WHERE id=?", new RowMapper<Profile>() { @Override/*from ww w. ja va 2 s .co m*/ public Profile mapRow(ResultSet resultSet, int i) throws SQLException { Array boxes = resultSet.getArray("main"); if (boxes != null) { return new Profile( new ProfileHashtable(DefaultProfile.getDefaultProfile(), (Map<String, String>) resultSet.getObject("settings")), Arrays.asList((String[]) boxes.getArray())); } else { return new Profile(new ProfileHashtable(DefaultProfile.getDefaultProfile(), (Map<String, String>) resultSet.getObject("settings")), null); } } }, user.getId()); if (profiles.isEmpty()) { return new Profile( new ProfileHashtable(DefaultProfile.getDefaultProfile(), new HashMap<String, String>()), null); } else { return profiles.get(0); } }
From source file:com.jaxio.celerio.configuration.database.mysql.MysqlEnumExtension.java
private void processEnums(JdbcTemplate jdbcTemplate, final Metadata metadata, final Table table) { jdbcTemplate.query("show columns from " + table.getName() + " where type like 'enum%'", new RowMapper<Void>() { @Override// w ww.j a va 2 s . co m public Void mapRow(ResultSet rs, int rowNum) throws SQLException { processEnumType(metadata, table, rs.getString("Field"), rs.getString("Type")); return null; } }); }
From source file:net.algem.util.CommonDao.java
public String findPhoto(int idper) throws DataAccessException { String query = "SELECT photo FROM " + PHOTO_TABLE + " WHERE idper = ?"; byte[] data = jdbcTemplate.queryForObject(query, new RowMapper<byte[]>() { @Override// w w w .ja va 2 s . c o m public byte[] mapRow(ResultSet rs, int i) throws SQLException { return rs.getBytes(1); } }, idper); return Base64.encodeBase64String(data); }
From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java
@Override public List<Purchase> getALL(boolean status) throws SQLException, ClassNotFoundException { String sql = "SELECT * FROM tbl_purchase WHERE 1=1"; if (status) { sql += " AND status=1 "; }/* ww w . j a va2s.co m*/ return jdbcTemplate.query(sql, new RowMapper<Purchase>() { @Override public Purchase mapRow(ResultSet rs, int i) throws SQLException { Purchase p = new Purchase(); p.setId(rs.getInt("purchase_id")); p.setProductName(rs.getString("product_name")); p.setCostPrice(rs.getInt("cost_price")); p.setDiscount(rs.getBigDecimal("discount")); p.setQuantity(rs.getInt("quantity")); p.setTotalCost(rs.getInt("total_cost")); p.setSupplierId(rs.getInt("supplier_id")); p.setPurchaseDate(rs.getDate("purchase_date")); p.setPaymentMethod(rs.getString("payment_method")); p.setStatus(rs.getBoolean("status")); return p; } }); }
From source file:com.havoc.hotel.admin.dao.impl.CommentsDAOImpl.java
@Override public List<Comments> getALL() throws SQLException { return jdbcTemplate.query(SQLConstant.COMMENTS_GETALL, new RowMapper<Comments>() { @Override//from ww w.j a v a2s.com public Comments mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }
From source file:com.leapfrog.academyspring.dao.impl.EnquiryDAOImpl.java
@Override public List<Enquiry> getAll() { return jdbcTemplate.query(SQLConstants.ENQUIRY_GETALL, new RowMapper<Enquiry>() { @Override/*from w ww .j a va2s.c o m*/ public Enquiry mapRow(ResultSet rs, int i) throws SQLException { Enquiry enq = new Enquiry(); enq.setId(rs.getInt("id")); enq.setFirstName(rs.getString("first_name")); enq.setLastName(rs.getString("last_name")); enq.setEmail(rs.getString("email")); enq.setContactNo(rs.getString("contact_no")); enq.setCourseId(rs.getInt("course_id")); enq.setMessage(rs.getString("message")); enq.setEnquiryDate(rs.getDate("enquiry_date")); enq.setIsRead(rs.getBoolean("is_read")); enq.setParentId(rs.getInt("parent_id")); return enq; } }); }
From source file:ru.org.linux.auth.IPBlockDao.java
public IPBlockInfo getBlockInfo(String addr) { List<IPBlockInfo> list = jdbcTemplate.query( "SELECT ip, reason, ban_date, date, mod_id, allow_posting, captcha_required FROM b_ips WHERE ip = ?::inet", new RowMapper<IPBlockInfo>() { @Override//from w w w . ja va 2 s.co m public IPBlockInfo mapRow(ResultSet rs, int rowNum) throws SQLException { return new IPBlockInfo(rs); } }, addr); if (list.isEmpty()) { return new IPBlockInfo(addr); } else { return list.get(0); } }
From source file:de.olivergierke.spring4.java8.JdbcRepository.java
public void executeQueryWithPreparedStatementAndRowMapper() { template.query("SELECT name, age FROM person WHERE dep = ?", ps -> ps.setString(1, "Sales"), (rs, rowNum) -> new Person(rs.getString(1), rs.getString(2))); // VS./*from w ww . j a v a 2 s .c o m*/ template.query("SELECT name, age FROM person WHERE dep = ?", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, "Sales"); } }, new RowMapper<Person>() { @Override public Person mapRow(ResultSet resultSet, int i) throws SQLException { return new Person(rs.getString(1), rs.getString(2)); } }); }
From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java
@Override public List<Customer> getALL() throws SQLException { return jdbcTemplate.query(SQLConstant.CUSTOMER_GETALL, new RowMapper<Customer>() { @Override/*from ww w . j a v a 2s. c o m*/ public Customer mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }