Spring jdbcTemplate.update example

      Click here to attend Spring Framework 4.x and certification course with a discount

     public boolean changeUserPassword(final String email,final String newPass) {
    	final String SQL = "UPDATE `kameroom`.`user` set `password`=?" +
				" WHERE `email`=?";
    	int result = jdbcTemplate.update(
                 new PreparedStatementCreator() {
                     public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                         PreparedStatement ps =connection.prepareStatement(SQL);
                       //Encrypt 1000 times
                 		PasswordEncoder passEncoder = new ShaPasswordEncoder(256);
                 		String salt = email;
                 		String pass= newPass;
                 		for (int i = 0; i < 1000; i++) {
                 			pass = passEncoder.encodePassword(newPass, salt);
                         ps.setString(1, pass);
                         ps.setString(2, email);
                         return ps;
    	if(result == 1)
    	return true;
    	return false;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s