Package org.springframework.jdbc.core

Examples of org.springframework.jdbc.core.PreparedStatementCreator


      final BagOfWordsData bagOfWordsData) {
    txNew.execute(new TransactionCallback<Object>() {

      @Override
      public Object doInTransaction(TransactionStatus txStatus) {
        jdbcTemplate.query(new PreparedStatementCreator() {

          @Override
          public PreparedStatement createPreparedStatement(
              Connection conn) throws SQLException {
            return conn.prepareStatement(sql,
View Full Code Here


   * @param sql
   * @param args
   */
  protected long insertWithIdReturn(final String sql, final Object... args) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
        PreparedStatement ps = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        for (int i = 1; i <= args.length; i++) {
          ps.setObject(i, args[i - 1]);
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  protected <T extends Number> List<T> batchInsertWithIdReturn(final String sql, final List<Object[]> argsList) {
    Assert.notEmpty(argsList, "args can not be empty while batch insert");
    final KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.execute(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
        PreparedStatement ps = con.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        return ps;
      }
View Full Code Here

  }

  @Override
  public int update(String sql, KeyHolder keyHolder, Object... args) {
    boolean returnKeys = (keyHolder != null);
    PreparedStatementCreator psc = getPreparedStatementCreator(sql, args, returnKeys);
    if (keyHolder == null) {
      return jdbcTemplate.update(psc);
    } else {
      return jdbcTemplate.update(psc, getWrapperKeyHolder(keyHolder));
    }
View Full Code Here

  @Override
  public int[] batchUpdate(String sql, List<Object[]> argsList, KeyHolder generatedKeyHolder) {
    BatchPreparedStatementSetter pss = getBatchPreparedStatementSetter(argsList);
    PreparedStatementCallback<int[]> action = getPreparedStatementCallback(pss, generatedKeyHolder);
    boolean returnKeys = (generatedKeyHolder != null);
    PreparedStatementCreator psc = getPreparedStatementCreator(sql, returnKeys);
    return jdbcTemplate.execute(psc, action);
  }
View Full Code Here

  private PreparedStatementCreatorFactory() {
   
  }
 
  public static PreparedStatementCreator createPreparedStatementCreator(final String sql, final boolean returnKeys) {
    PreparedStatementCreator creator = new PreparedStatementCreator() {

      @Override
      public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
        PreparedStatement ps = con.prepareStatement(sql);
        if (returnKeys) {
View Full Code Here

    return creator;
  }

  public static PreparedStatementCreator createPreparedStatementCreator(final String sql, final Object[] args,
      final boolean returnKeys) {
    PreparedStatementCreator creator = new PreparedStatementCreator() {

      @Override
      public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
        PreparedStatement ps = con.prepareStatement(sql);
        if (returnKeys) {
View Full Code Here

 
  @Transactional
  @Override
  public void create(final InformationForm infoForm) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("information")+ "(sort_order, bottom, status) VALUES(?,?,?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
View Full Code Here

 
  @Transactional
  @Override
  public void create(final AttributeGroupForm attrGrpForm) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("attribute_group")+ "(sort_order) VALUES(?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
View Full Code Here

 
  @Transactional
  @Override
  public void create(final AttributeForm attrForm) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("attribute")+ "(attribute_group_id, sort_order) VALUES(?, ?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.PreparedStatementCreator

Copyright © 2018 www.massapicom. 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.