Examples of PreparedStatementCreator


Examples of org.springframework.jdbc.core.PreparedStatementCreator

   
    public User createUser(final User user) {
        final String sql = "insert into oauth2_user(username, password, salt) values(?,?,?)";

        GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement psst = connection.prepareStatement(sql, new String[]{"id"});
                int count = 1;
                psst.setString(count++, user.getUsername());
View Full Code Here

Examples of org.springframework.jdbc.core.PreparedStatementCreator

        logger.debug("SQL for Save: " + sql);
        int updateCount = 0;
        if (isNewRow && persistentObject.isUsingGeneratedKeysStrategy()) {
            KeyHolder keyHolder = new GeneratedKeyHolder();
            final String prepSql = sql.toString();
            updateCount = getJdbcTemplate().update(new PreparedStatementCreator() {
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                    PreparedStatement ps = con.prepareStatement(prepSql, Statement.RETURN_GENERATED_KEYS);
                    int cnt = 0;
                    for (Iterator iter = parameterValues.iterator(); iter.hasNext(); ) {
                        PersistentValue pv = (PersistentValue)iter.next();
                        StatementCreatorUtils.setParameterValue(ps, cnt+1, pv.getSqlType(), null, pv.getValue());
                        cnt++;
                    }
                    return ps;
                }
            }, keyHolder);
            assignGeneratedKey(o, keyHolder);
        }
        else {
            final String prepSql = sql.toString();
            updateCount = getJdbcTemplate().update(new PreparedStatementCreator() {
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                    PreparedStatement ps = con.prepareStatement(prepSql);
                    int cnt = 0;
                    for (Iterator iter = parameterValues.iterator(); iter.hasNext(); ) {
                        PersistentValue pv = (PersistentValue)iter.next();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.