List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.sktelecom.cep.notebook.repo.JDBCNotebookRepo.java
@Override public Note get(String noteId) throws IOException { try {//w w w . j a v a 2s .c o m StringBuffer sb = new StringBuffer(); sb.append("select nb.note_id, nb.note_name, nb.note_content, wo.own_user_id as user_id "); sb.append(" from notebook nb "); sb.append(" inner join workspace_object wo on wo.wrkspc_obj_id = nb.wrkspc_obj_id "); sb.append(" where nb.note_id = ? "); Note note = jdbcTemplate.queryForObject(sb.toString(), new Object[] { noteId }, new RowMapper<Note>() { public Note mapRow(ResultSet rs, int rowNum) throws SQLException { Note note = null; try { note = getNote(rs.getString("note_content")); note.setUserId(rs.getString("user_id")); note.setName(rs.getString("note_name")); } catch (IOException e) { e.printStackTrace(); } return note; } }); return note; } catch (EmptyResultDataAccessException e) { return null; } }
From source file:com.sfs.whichdoctor.dao.AccreditationDAOImpl.java
/** * Load the AccreditationBean.//from w w w . j a va 2 s . c om * * @param accreditationId the accreditation id * * @return the accreditation bean * * @throws WhichDoctorDaoException the which doctor dao exception */ public final AccreditationBean load(final int accreditationId) throws WhichDoctorDaoException { dataLogger.info("Getting accreditationId:" + accreditationId); final String loadAccreditationId = getSQL().getValue("accreditation/load") + " WHERE accreditation.AccreditationId = ?"; AccreditationBean accreditation = null; try { accreditation = (AccreditationBean) this.getJdbcTemplateReader().queryForObject(loadAccreditationId, new Object[] { accreditationId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadAccreditation(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for search: " + ie.getMessage()); } return accreditation; }
From source file:com.sfs.whichdoctor.dao.BulkEmailDAOImpl.java
/** * Used to get a BulkEmailBean for a specified BulkEmailId. * * @param bulkEmailId the bulk email id/*from w w w. j a v a 2 s .c om*/ * @param loadDetails the load details * @return the bulk email bean * @throws WhichDoctorDaoException the which doctor dao exception */ public final BulkEmailBean load(final int bulkEmailId, final BuilderBean loadDetails) throws WhichDoctorDaoException { dataLogger.info("BulkEmailId: " + bulkEmailId + " requested"); final String loadId = getSQL().getValue("bulkEmail/load") + " WHERE bulk_email.BulkEmailId = ? GROUP BY bulk_email.GUID"; BulkEmailBean bulkEmail = null; try { bulkEmail = (BulkEmailBean) this.getJdbcTemplateReader().queryForObject(loadId, new Object[] { bulkEmailId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadBulkEmail(rs, loadDetails); } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search dataLogger.error("No result found for BulkEmailBean search", ie); } return bulkEmail; }
From source file:sf.wicklet.site.gwt.test.db.TestSpringJDBCH201.java
@Test public void test02() throws SQLException, ClassNotFoundException { final String dbpath2 = new File("trash/TestSpringJDBCH201/db02").getAbsolutePath(); final File dbfile2 = new File(dbpath2 + ".h2.db"); dbfile2.delete();// w w w. j a v a 2s . c o m Assert.assertFalse(dbfile2.exists()); DbSupport dao = new DbSupport(createDatabase(dbfile2, dbpath2)); try { final JdbcTemplate t = dao.getJdbcTemplate(); final List<StringPair> ret = t.query("SELECT * from User, Address where User.addressId = Address.id", new RowMapper<StringPair>() { @Override public StringPair mapRow(final ResultSet rs, final int rowNum) throws SQLException { return new StringPair(rs.getString("name"), rs.getString("address")); } }); Assert.assertEquals(3, ret.size()); } finally { dao.shutdown(); } Assert.assertTrue(dbfile2.exists()); // Try again with existing dbfile. dao = new DbSupport(createDatabase(dbfile2, dbpath2)); try { final JdbcTemplate t = dao.getJdbcTemplate(); final List<StringPair> ret = t.query("SELECT * from User, Address where User.addressId = Address.id", new RowMapper<StringPair>() { @Override public StringPair mapRow(final ResultSet rs, final int rowNum) throws SQLException { return new StringPair(rs.getString("name"), rs.getString("address")); } }); Assert.assertEquals(3, ret.size()); } finally { dao.shutdown(); } }
From source file:dao.CircleDAO.java
public List<String> getComments(int postId) { String query =// w ww . ja v a2 s . c om "SELECT CommentId" + "\nFROM gets" + "\nWHERE PostId = " + postId; List<Integer> commentIds = this.jdbcTemplate.query(query, new RowMapper<Integer>() { @Override public Integer mapRow(ResultSet rs, int rowNum) throws SQLException { int commentId = rs.getInt("CommentId"); return commentId; } }); List<String> comments = null; for (int id : commentIds) { String q = "SELECT a.UserId, b.Content, b.Date\n" + "\nFROM makes a, comment b\n" + "\nWHERE a.CommentId =" + id + " AND b.CommentId =" + id; comments = this.jdbcTemplate.query(q, new RowMapper<String>() { @Override public String mapRow(ResultSet rs, int rowNum) throws SQLException { String s = ""; s += rs.getInt("UserId") + " " + rs.getDate("Date").toString() + "\n " + rs.getString("Content"); return s; } }); } return comments; }
From source file:com.xinferin.dao.DAOProductImpl.java
@Override public List<Product> list() { String sql = "SELECT * FROM product"; List<Product> list = jdbcTemplate.query(sql, new RowMapper<Product>() { @Override/*from w w w . java2 s . c o m*/ public Product mapRow(ResultSet rs, int rowNum) throws SQLException { Product aProduct = new Product(); aProduct.setId(rs.getInt("id")); aProduct.setName(rs.getString("name")); aProduct.setLicence_params(rs.getBytes("licence_params")); return aProduct; } }); return list; }
From source file:om.edu.squ.squportal.portlet.dps.dao.db.DpsDbImpl.java
/** * //from w w w . java2s. c o m * method name : getEmployee * @param empNumber * @return * DpsDbImpl * return type : Employee * * purpose : * * Date : Jan 8, 2017 3:42:44 PM * @throws ExceptionEmptyResultset */ public Employee getEmployee(String empNumber) throws ExceptionEmptyResultset { String SQL_DPS_EMPLOYEE_DETAIL = queryProps.getProperty(Constants.COST_SQL_DPS_EMPLOYEE_DETAIL); RowMapper<Employee> mapper = new RowMapper<Employee>() { public Employee mapRow(ResultSet rs, int rowNum) throws SQLException { Employee employee = new Employee(); Branch branch = new Branch(); Department department = new Department(); employee.setEmpNumber(rs.getString(Constants.COST_COL_DPS_EMP_NO)); department.setDeptCode(rs.getString(Constants.COST_COL_DPS_DEPT_CODE)); branch.setBranchCode(rs.getString(Constants.COST_COL_DPS_BRANCH_CODE)); employee.setDepartment(department); employee.setBranch(branch); employee.setEmail(Constants.COST_COL_DPS_EMP_EMAIL); return employee; } }; Map<String, String> mapParamsDPS = new HashMap<String, String>(); mapParamsDPS.put("paramEmpNumber", empNumber); try { return nPJdbcTemplDps.queryForObject(SQL_DPS_EMPLOYEE_DETAIL, mapParamsDPS, mapper); } catch (EmptyResultDataAccessException ex) { logger.error("Empty resultset error. Details : " + ex.getMessage()); throw new ExceptionEmptyResultset(ex.getMessage()); } }
From source file:com.github.dbourdette.glass.log.joblog.jdbc.JdbcJobLogStore.java
private List<JobLog> getLogs(String sqlBase, SqlParameterSource params) { String sql = "select * " + sqlBase + " order by logDate asc"; return jdbcTemplate.query(sql, params, new RowMapper<JobLog>() { @Override/*from w ww .ja v a 2 s . c o m*/ public JobLog mapRow(ResultSet rs, int rowNum) throws SQLException { return doMapRow(rs, rowNum); } }); }
From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java
@SuppressWarnings("unchecked") public List<String> getDistinctSiteTerms(String termField) { try {/* www. j a v a 2 s.c o m*/ return getJdbcTemplate().query(getStatement("select.distinctTerms"), new String[] { termField }, new RowMapper() { public Object mapRow(ResultSet resultSet, int i) throws SQLException { return resultSet.getString(1); } }); } catch (DataAccessException ex) { log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex); return null; } }
From source file:ru.org.linux.poll.PollDao.java
/** * ?? ?? ??.//from w w w .ja va 2 s . co m * ? ? id * * @param pollId ?? * @return ?? ?? */ private List<PollVariant> getVoteDTO(int pollId) { return jdbcTemplate.query(queryPollVariantsOrderById, new RowMapper<PollVariant>() { @Override public PollVariant mapRow(ResultSet rs, int rowNum) throws SQLException { return new PollVariant(rs.getInt("id"), rs.getString("label")); } }, pollId); }