List of usage examples for org.springframework.jdbc.core ResultSetExtractor ResultSetExtractor
ResultSetExtractor
From source file:com.banking.controller.AddressController.java
public Address getAddress() { return jdbcTemplate.query( "SELECT address_id FROM customer_address " + "ORDER BY address_id " + "DESC LIMIT 1", new ResultSetExtractor<Address>() { @Override// ww w. j a va2 s . c o m public Address extractData(ResultSet rs) throws SQLException, DataAccessException { Address address = new Address(); if (rs.next()) { address.setId(rs.getInt(1)); } return address; } }); }
From source file:com.banking.controller.CustomerController.java
public List<Customer> list() { return jdbcTemplate.query("SELECT * FROM customer_table WHERE " + "customer_isactive='1' " + "ORDER BY " + "customer_firstname ASC", new ResultSetExtractor<List<Customer>>() { @Override// ww w . ja va 2 s . c o m public List<Customer> extractData(ResultSet rs) throws SQLException, DataAccessException { List<Customer> customers = new ArrayList<>(); while (rs.next()) { Customer customer = new Customer(); customer.setId(rs.getInt("customer_id")); customer.setFirstName(rs.getString("customer_firstname")); customer.setMiddleName(rs.getString("customer_middlename")); customer.setLastName(rs.getString("customer_lastname")); customer.setPhone(rs.getString("customer_homecontact")); customer.setDateOfBirth(rs.getString("customer_dateofbirth")); customer.setDateOfJoin(rs.getString("customer_dateofjoin")); customer.setAddressId(rs.getInt("customer_addressid")); customers.add(customer); } return customers; } }); }
From source file:com.ex.Dao.impl.GroupDaoImpl.java
@Override public Group findGroupById(String id) { String sql = "SELECT * FROM " + dbName + " WHERE GROUP_ID = '" + id + "'"; return jdbcTemplate.query(sql, new ResultSetExtractor<Group>() { @Override//from ww w. j a v a 2 s. com public Group extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { Group group = new Group(); group.setId(rs.getString("group_id")); group.setVersion(rs.getLong("version")); group.setXml(rs.getString("xml")); group.setGroupName(rs.getString("group_name")); group.setCreatedBy(rs.getString("created_by")); group.setUpdatedAt(rs.getTimestamp("updated_at")); return group; } return null; } }); }
From source file:com.banking.controller.EmployeeController.java
public List<Employee> list() { return jdbcTemplate.query( "SELECT * FROM employee_table WHERE employee_isactive='1' ORDER BY employee_firstname ASC", new ResultSetExtractor<List<Employee>>() { @Override//from w w w.j av a 2s . com public List<Employee> extractData(ResultSet rs) throws SQLException, DataAccessException { List<Employee> list = new ArrayList<>(); while (rs.next()) { Employee employee = new Employee(); employee.setId(rs.getInt("employee_id")); employee.setFirstName(rs.getString("employee_firstname")); employee.setMiddleName(rs.getString("employee_middlename")); employee.setLastName(rs.getString("employee_lastname")); employee.setHomeContact(rs.getString("employee_homecontact")); employee.setMobileNumber(rs.getString("employee_mobilecontact")); employee.setDateOfBirth(rs.getString("employee_dateofbirth")); employee.setDateOfJoin(rs.getString("employee_dateofjoin")); employee.setAddressId(rs.getInt("employee_address")); String post = rs.getString("employee_post"); employee.setPost(EmployeePost.valueOf(post)); list.add(employee); } return list; } }); }
From source file:com.javacodegags.waterflooding.model.FloodingImplemented.java
@Override public Flooding get(int criteriaId) { String sql = "SELECT flooding.id, flooding.name, flooding.image, flooding.description " + "FROM intermediatetoflooding " + "INNER JOIN criteria " + "ON intermediatetoflooding.foreign_to_criteria=criteria.Id " + "INNER JOIN flooding " + "ON intermediatetoflooding.foreign_to_flooding=flooding.id " + "Where criteria.id=" + criteriaId + ";"; Flooding flooding = jdbcTemplate.query(sql, new ResultSetExtractor<Flooding>() { @Override/* w w w .jav a2s . co m*/ public Flooding extractData(ResultSet rs) throws SQLException, DataAccessException { Flooding flooding = new Flooding(); if (rs.next()) { flooding.setId(rs.getInt("id")); flooding.setName(rs.getString("name")); flooding.setImage(rs.getString("image")); flooding.setDescription(rs.getString("description")); } return flooding; } }); return flooding; }
From source file:com.xinferin.dao.DAOProviderImpl.java
@Override public Provider get(String provider) { String sql = "SELECT * FROM provider WHERE name = '" + provider + "'"; return jdbcTemplate.query(sql, new ResultSetExtractor<Provider>() { @Override// w ww . ja va2 s . c o m public Provider extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { Provider provider = new Provider(); provider.setId(rs.getInt("id")); provider.setName(rs.getString("name")); return provider; } return null; } }); }
From source file:com.banking.controller.AddressController.java
public Address findById(int addressId) { return jdbcTemplate.query("SELECT * FROM customer_address " + "WHERE " + "address_id='" + addressId + "'", new ResultSetExtractor<Address>() { @Override/*from ww w. j a v a 2 s .c om*/ public Address extractData(ResultSet rs) throws SQLException, DataAccessException { Address address = new Address(); if (rs.next()) { address.setCity(rs.getString("city")); address.setState(rs.getString("state")); address.setZipCode(rs.getString("zip_code")); } return address; } }); }
From source file:de.whs.poodle.repositories.CourseStatisticsRepository.java
public CourseStatistics getForCourse(int courseId) { return jdbc.query("SELECT * FROM get_course_statistics(?)", new Object[] { courseId }, new ResultSetExtractor<CourseStatistics>() { @Override//from www . jav a 2s .c o m public CourseStatistics extractData(ResultSet rs) throws SQLException { CourseTermStatisticsRowMapper rowMapper = new CourseTermStatisticsRowMapper(); CourseStatistics courseStatistics = new CourseStatistics(); while (rs.next()) { TotalCourseTermStatistics cts = rowMapper.mapRow(rs, 0); cts.setEnrolledStudentCount(rs.getInt("enrolled_students")); CourseTerm ct = courseTermRepo.getById(rs.getInt("course_term_id")); courseStatistics.addTotalCourseTermStatistics(ct, cts); } return courseStatistics; } }); }
From source file:com.javacodegags.waterflooding.model.CriteriaImplemented.java
@Override public Criteria get(int criteriaId) { String sql = "SELECT criteria.id, criteria.criteria_value,criteria.weight_factor, criteria.formula, caption.argument,criteria.foreign_to_therm " + "FROM intermediate " + "INNER JOIN geology.caption " + "ON geology.intermediate.foreign_to_caption=geology.caption.Id " + "INNER JOIN geology.criteria " + "ON geology.intermediate.foreign_to_criteria=geology.criteria.Id " + "where criteria.Id=" + criteriaId + ";"; return jdbcTemplate.query(sql, new ResultSetExtractor<Criteria>() { @Override//from w w w . j a v a 2 s .c o m public Criteria extractData(ResultSet rs) throws SQLException, DataAccessException { Criteria criteria = new Criteria(); if (rs.next()) { criteria.setId(rs.getInt("id")); criteria.setValue(rs.getDouble("criteria_value")); criteria.setArgument(rs.getDouble("argument")); criteria.setFormula(rs.getString("formula")); criteria.setWeighFactor(rs.getDouble("weight_factor")); criteria.setTherms(rs.getInt("foreign_to_therm")); } return criteria; } }); }
From source file:com.mysoft.b2b.solr.db.ScoreReader.java
@Override public void run() { String sql = "select * from supplier_intervent_score "; try {/*from w ww . j a va 2 s.co m*/ scoreList = jdbcTemplate.query(sql, new ResultSetExtractor<Map<String, Object>>() { @Override public Map<String, Object> extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { scoreList.put(rs.getString("supplierId"), rs.getInt("score")); } return scoreList; } }); } catch (Exception e) { System.out.println("supplier_intervent_score?."); } }