Java Iterable createUpdateTemplate(String table, Iterable columns)

Here you can find the source of createUpdateTemplate(String table, Iterable columns)

Description

A static helper method for generating SQL templates for UPDATE statements for the provided column colection or array

License

Open Source License

Declaration

public static String createUpdateTemplate(String table, Iterable<String> columns) 

Method Source Code

//package com.java2s;

import java.util.Iterator;

public class Main {
    /**/*from   w  w  w. ja  v  a 2s .c  o m*/
     * A static helper method for generating SQL templates for UPDATE
     * statements for the provided column colection or array
     *
     * @note: This method returns templates that do not have WHERE clauses. It's
     * up to the caller to append an appropriate WHERE clause, or else executing 
     * the resulting query will update every single row in the table.
     */
    public static String createUpdateTemplate(String table, Iterable<String> columns) {
        //
        StringBuilder builder = new StringBuilder();

        builder.append("update ").append(table).append(" set ");

        Iterator<String> it = columns.iterator();
        while (it.hasNext()) {
            builder.append(it.next()).append(" = ?");

            if (it.hasNext())
                builder.append(", ");
        }
        return builder.append(" ").toString();
    }
}

Related

  1. appendTo(StringBuilder appendable, Iterable parts, CharSequence separator)
  2. commafy(Iterable col, StringBuilder builder)
  3. containsSame(Iterable coll, Object obj)
  4. convertIterable(final Iterable> iterables)
  5. createDelimitedString(Iterable iterable, String delimiter)
  6. equal(Iterable it1, Iterable it2)
  7. equalsIterablesInOrder(Iterable i1, Iterable i2)
  8. fillFromIterable(C c, Iterable i)
  9. getAny(Iterable iterable)