Package org.springframework.jdbc.core.namedparam

Examples of org.springframework.jdbc.core.namedparam.SqlParameterSource


      List<T> dataList = dbTable.getTableData();
      if(null == dataList || dataList.size() < 1) return;
      Map<String, String> idMap = new HashMap<String, String>();
      String id = "";
      String countSql = "";
      SqlParameterSource sqlParameterSource;
      List<Map<String, Object>> idList = new ArrayList<Map<String,Object>>();
      for (T t : dataList) {
        ReflectHelper reflectHelper = new ReflectHelper(t);
        List<String> ignores = new ArrayList<String>();
        ignores.add("class");
View Full Code Here


  }
  public Object executeSqlReturnKey(final String sql, Map<String, Object> param) {
    Object keyValue = null;
    try{
      KeyHolder keyHolder = new GeneratedKeyHolder();
      SqlParameterSource sqlp  = new MapSqlParameterSource(param);
      this.namedParameterJdbcTemplate.update(sql,sqlp, keyHolder);
      keyValue = keyHolder.getKey().longValue();
    }catch (Exception e) {
      keyValue = null;
    }
View Full Code Here

  public int updateObject(String sql, Object object) throws DataAccessException {
    if (debug) {
      logger.info("sql:" + sql);
      logger.info("object:" + object);
    }
    SqlParameterSource namedParam = new BeanPropertySqlParameterSource(object);
    KeyHolder keyHolder = new GeneratedKeyHolder();
    int ret = getNameParameterJdbcTemplate().update(sql, namedParam, keyHolder);
    if (ret <= 0)
      return ret;
    try {
View Full Code Here

    assertEquals(666, result);
  }

  @Test
  public void testQueryForIntWitSqlParameterSource() {
    SqlParameterSource args = new MapSqlParameterSource().addValue("id", 24).addValue("xy", "foo");
    given(namedParameterOperations.queryForInt(SQL, args)).willReturn(666);
    int result = namedParameterTemplate.queryForInt(SQL, args);
    assertEquals(666, result);
  }
View Full Code Here

  * @throws DataAccessException
  */
  public int insertUser(User user) throws DataAccessException{
     String sql = "insert into bu_user(user_name,password,position_num,add_user,add_time,last_login,del,nickname) "
        + "values (:userName,password(:password),:positionNum,:addUser,now(),now(),0,:nickName)";
     SqlParameterSource paramMap = new BeanPropertySqlParameterSource(user);
    return namedParameterJdbcTemplate.update(sql, paramMap);
   }
View Full Code Here

   * @return
   */
  @TriggersRemove(cacheName = "codeCache", removeAll = true)
  public int insertCode(Code code) {
    String sql = "insert into sys_code(group_name,`key`,`value`,parent_key,last_modify) values (:groupName,:key,:value,:parentKey,now())";
    SqlParameterSource paramMap = new BeanPropertySqlParameterSource(code);
    return namedParameterJdbcTemplate.update(sql, paramMap);
  }
View Full Code Here

   * @return
   * @throws DataAccessException
   */
  public int deleteUser(String userName) throws DataAccessException {
    String sql = "update bu_user set del = 1 where user_name = :userName";
    SqlParameterSource paramMap = new MapSqlParameterSource("userName", userName);
    return namedParameterJdbcTemplate.update(sql, paramMap);
  }
View Full Code Here

        + " where bu_user.del = 0 and  bu_user.user_name = :userName and "
        + "bu_user.password = password(:password)";
    Map<String, String> map = new HashMap<String, String>();
    map.put("userName", userName);
    map.put("password", password);
    SqlParameterSource paramMap = new MapSqlParameterSource(map);
    RowMapper<User> mapper = new UserMapper();
    try{
      return (User) namedParameterJdbcTemplate.queryForObject(sql, paramMap, mapper);
    }catch (EmptyResultDataAccessException e){
      return null;
View Full Code Here

   * @param userName
   * @return
   */
  public int deleteUserComplete(String userName) {
    String sql = "delete from bu_user where user_name = :userName";
    SqlParameterSource paramMap = new MapSqlParameterSource("userName", userName);
    return namedParameterJdbcTemplate.update(sql, paramMap);
  }
View Full Code Here

   */
  public int updateUserInfo(User user) {
    String sql = "update bu_user set position_num=:positionNum ,"
        + " email=:email , telephone=:telephone , mobile=:mobile , nickname=:nickName "
        + "where user_name = :userName";
    SqlParameterSource paramMap = new BeanPropertySqlParameterSource(user);
    return namedParameterJdbcTemplate.update(sql, paramMap);
  }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.namedparam.SqlParameterSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.