use of org.springframework.jdbc.support.KeyHolder in project dal by ctripcorp.
the class DaoOfLoginUser method insertUser.
public int insertUser(final LoginUser user) {
if (user == null || user.getUserNo() == null) {
return -1;
}
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement("INSERT INTO login_users ( user_no, user_name, user_email, password ) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE user_no = ?", Statement.RETURN_GENERATED_KEYS);
ps.setString(1, user.getUserNo());
ps.setString(2, user.getUserName());
ps.setString(3, user.getUserEmail());
ps.setString(4, user.getPassword());
ps.setString(5, user.getUserNo());
return ps;
}
}, holder);
return holder.getKey().intValue();
}
use of org.springframework.jdbc.support.KeyHolder in project dal by ctripcorp.
the class DaoOfUserProject method insertUserProject.
public int insertUserProject(final UserProject data) {
KeyHolder holder = new GeneratedKeyHolder();
this.jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement("INSERT INTO user_project (project_id, user_no ) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, data.getProject_id());
ps.setString(2, data.getUserNo());
return ps;
}
}, holder);
return holder.getKey().intValue();
}
Aggregations