spring getJdbcTemplate

//新增
@Override
public int insertSalaryInfo(final SalaryInfo s) {
	String sql="insert into offical_salary(user_id,qq_num,nickname,user_level,salary) values(?,?,?,?,?)";
	
	return this.getJdbcTemplate().update(sql, new PreparedStatementSetter() {
		public void setValues(PreparedStatement ps) throws SQLException {
			ps.setInt(1, s.getUserId());
			ps.setString(2, s.getQqNum());
			ps.setString(3, s.getNickName());
			ps.setInt(4, s.getUserLevel());
			ps.setInt(5, s.getSalary());
		}
	});
}

//删除
@Override
public void deleteLimitHousInfos(int hours) {
	String sql = "delete from user_present_conch where add_time between < DATE_FORMAT(ADDDATE(NOW(), INTERVAL -? HOUR),'%Y-%m-%d %H')";
	getJdbcTemplate().update(sql, new Object[]{hours});
}

//更新
@Override
public int UpdateDayQuestion(int userId, String roomId, String title, String chioceA, String chioceB, String chioceC, String chioceD, String answer){
	String sql = "UPDATE daily_question SET user_id = ?,  title = ?, choiceA = ?, choiceB= ?,  choiceC = ?, choiceD= ?, answer=? WHERE room_id = ?";
	int result = this.getJdbcTemplate().update(sql, new Object[]{userId, title, chioceA, chioceB, chioceC, chioceD, answer, roomId});
	return result;
}

//查询1
@Override
public boolean hasFollowing(int followingId, int followedId) {
	String sql = "select count(following_id) from user_following where user_id = ? and following_id = ?";
	int count = this.getJdbcTemplate().queryForInt(sql, followingId,followedId);
	return count > 0;
}

//查询2
@Override
public List<UserFollowing> getUserFollowingList(int userId) {
	String sql ="select * from user_following where user_id=?";
	List<UserFollowing> userFollowings=this.getJdbcTemplate().query(sql, new Object[]{userId}, org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper.newInstance(UserFollowing.class));
	return userFollowings;
}

你可能感兴趣的:(spring getJdbcTemplate)