Example usage for org.springframework.jdbc.core PreparedStatementCreator PreparedStatementCreator

List of usage examples for org.springframework.jdbc.core PreparedStatementCreator PreparedStatementCreator

Introduction

In this page you can find the example usage for org.springframework.jdbc.core PreparedStatementCreator PreparedStatementCreator.

Prototype

PreparedStatementCreator

Source Link

Usage

From source file:net.freechoice.model.orm.Map_Transaction.java

@Override
public PreparedStatementCreator createUpdate(final FC_Transaction entity) {

    return new PreparedStatementCreator() {

        @Override//  ww w .  ja v a2 s .  c o m
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

            PreparedStatement ps = con.prepareStatement("update  FC_Transaction" + " set  id_account_ = ?,"
                    + " amount = ?, " + " comment = ? " + "where id = " + entity.id);
            ps.setInt(1, entity.id_account_);
            ps.setBigDecimal(2, entity.amount);
            ps.setString(3, entity.comment);
            return ps;
        }
    };
}

From source file:com.ccoe.build.dal.SessionProjectJDBCTemplate.java

public int create(final int sessionID, final int projectID) {
    final String SQL = "insert into RBT_SESSION_PROJECT (session_id, project_id) values (?, ?)";

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplateObject.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" });
            ps.setInt(1, sessionID);//from  w w w. ja  va2  s  .c om
            ps.setInt(2, projectID);

            return ps;
        }
    }, keyHolder);

    return keyHolder.getKey().intValue();
}

From source file:net.freechoice.model.orm.Map_Post.java

/**
 * for content update see Dao_Post//ww  w  .j  a  v a  2  s .c  o m
 */
@Override
public PreparedStatementCreator createUpdate(final FC_Post entity) {

    return new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

            PreparedStatement ps = con.prepareStatement(" update  FC_Post " + " set   status = ?,"
                    + "     id_author = ?, " + "     name_author = ?, " + "     title = ? " + " where id = ? ");
            ps.setShort(1, entity.status);
            ps.setInt(2, entity.id_author);
            ps.setString(3, entity.name_author);
            ps.setString(4, entity.title);
            ps.setInt(5, entity.id);
            return ps;
        }
    };
}

From source file:net.freechoice.model.orm.Map_User.java

@Override
public PreparedStatementCreator createUpdate(final FC_User user) {

    final String psw = EncryptionService.transformPassword(user.password);

    return new PreparedStatementCreator() {

        @Override/*from w w w. ja  v a2s  .c om*/
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

            PreparedStatement ps = con.prepareStatement(
                    "update fc_user set path_avatar = ?," + "name_login = ?," + "name_display = ?, "
                            + "email = ?, " + "password = ?, " + "tagline = ? " + " where id = ?");
            ps.setString(1, user.path_avatar);
            ps.setString(2, user.name_login);
            ps.setString(3, user.name_display);
            ps.setString(4, user.email);
            ps.setString(5, psw);
            ps.setString(6, user.tagline);
            ps.setInt(7, user.id);
            //System.err.println("--------  SQL  --------\n" + ps.toString());
            return ps;
        }
    };
}

From source file:edu.pitt.sis.infsci2730.finalProject.dao.AddressDao.java

/**
 * add new AddressDBModel/*from   ww w .j  ava  2 s. co m*/
 *
 * @param para
 * @return
 */
//    public static int addAddress(final String[] para) throws SQLException {
//        String sql = "insert into Address (city,street,state_,zipCode) values (?,?,?,?)";
//        return jdbcTemplate.update(sql,
//                para,
//                new int[]{java.sql.Types.VARCHAR, java.sql.Types.VARCHAR, java.sql.Types.VARCHAR, java.sql.Types.VARCHAR});
//    }

public static Long addAddress(final String[] para) throws SQLException {

    KeyHolder holder = new GeneratedKeyHolder();
    jdbcTemplate.update(new PreparedStatementCreator() {

        String sql = "insert into Address (city,street,state_,zipCode) values (?,?,?,?)";

        @Override
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            PreparedStatement ps = connection.prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS);
            ps.setString(1, para[0]);
            ps.setString(2, para[1]);
            ps.setString(3, para[2]);
            ps.setString(4, para[3]);
            return ps;
        }
    }, holder);

    Long newPersonId = holder.getKey().longValue();

    return newPersonId;
}

From source file:test.Test_db.java

@Test
public void sda() {

    Dao_Post postDao = new Dao_Post();
    postDao.setDataSource(cpds);/*www .j  a v a2  s . com*/

    String str = postDao.getJdbcTemplate().query(new PreparedStatementCreator() {

        @Override
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con.prepareStatement("select content from fc_post where id = 49");
            return ps;
        }
    }, new StrExtractor());
    System.err.println(str);
}

From source file:com.ccoe.build.dal.ProjectJDBCTemplate.java

public int create(final Project project, final String appName) {
    final String SQL = "insert into RBT_PROJECT (pool_name, name, group_id, artifact_id, type, version, "
            + "duration, status, start_time) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)";

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplateObject.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" });
            ps.setString(1, appName);/*from ww  w  .ja  v  a  2s  . co m*/
            ps.setString(2, project.getName());
            ps.setString(3, project.getGroupId());
            ps.setString(4, project.getArtifactId());
            ps.setString(5, project.getType());
            ps.setString(6, project.getVersion());
            ps.setLong(7, project.getDuration());
            ps.setString(8, project.getStatus());
            ps.setTimestamp(9, new java.sql.Timestamp(project.getStartTime().getTime()));

            return ps;
        }
    }, keyHolder);

    return keyHolder.getKey().intValue();
}

From source file:com.ccoe.build.dal.PluginJDBCTemplate.java

public int create(final Plugin plugin) {
    final String SQL = "insert into RBT_PLUGIN (plugin_key, group_id, artifact_id, version, phase) values (?, ?, ?, ?, ?)";

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplateObject.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" });
            ps.setString(1, plugin.getPluginKey());
            ps.setString(2, plugin.getGroupId());
            ps.setString(3, plugin.getArtifactId());
            ps.setString(4, plugin.getVersion());
            ps.setString(5, plugin.getPhaseName());

            return ps;
        }/* ww  w . j  a v  a  2 s . c  o m*/
    }, keyHolder);

    return keyHolder.getKey().intValue();
}

From source file:net.freechoice.model.orm.Map_Profile.java

@Override
public PreparedStatementCreator createUpdate(final FC_Profile entity) {

    return new PreparedStatementCreator() {

        @Override// w  w w.  j  a v  a  2  s  . c o  m
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

            PreparedStatement ps = con.prepareStatement(
                    "update  FC_Transaction" + " set  id_user_ = ? " + ",      site_personal = ? "
                            + ",     name_first = ? " + ",     name_last = ? " + ",     contact_public = ? "
                            + ",     gender = ? " + ",     date_birth = ? " + " where id = ?");
            ps.setInt(1, entity.id_user_);
            ps.setString(2, entity.site_personal);
            ps.setString(3, entity.name_first);
            ps.setString(4, entity.name_last);
            ps.setString(5, entity.contact_public);
            ps.setBoolean(6, entity.gender);
            ps.setDate(7, entity.date_birth);
            ps.setInt(8, entity.id);
            return ps;
        }
    };
}

From source file:io.spring.recommendation.service.TagServiceImpl.java

@Override
@Cacheable("tag")
public long getTagId(final String tag) {
    long id = -1;

    try {//  ww w . j  av  a  2  s.  co  m
        id = template.queryForObject("select id from TAG where TAG = ?", Long.class, tag);
    } catch (EmptyResultDataAccessException ignore) {
    }

    if (id < 0) {
        KeyHolder keyHolder = new GeneratedKeyHolder();

        template.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                PreparedStatement ps = con.prepareStatement("insert into TAG (VERSION, TAG) VALUES (1, ?)",
                        new String[] { "ID" });

                ps.setString(1, tag);

                return ps;
            }
        }, keyHolder);

        id = keyHolder.getKey().longValue();
    }

    return id;
}