Here you can find the source of createNamedInsert(String tableName, Collection
Parameter | Description |
---|---|
tableName | Table name. |
columnNames | Column names for insert. |
public static String createNamedInsert(String tableName, Collection<String> columnNames)
//package com.java2s; /***************************************************************************** * /*from w w w. j av a 2 s . c om*/ * Copyright (C) Zenoss, Inc. 2010, all rights reserved. * * This content is made available according to terms specified in * License.zenoss under the directory where your Zenoss product is installed. * ****************************************************************************/ import java.util.Collection; import java.util.Iterator; public class Main { /** * Create an insert SQL string for the table with the specified insert columns. * * @param tableName Table name. * @param columnNames Column names for insert. * @return An insert SQL statement with the names (suitable for passing to Spring named * parameter template). */ public static String createNamedInsert(String tableName, Collection<String> columnNames) { StringBuilder names = new StringBuilder(); StringBuilder values = new StringBuilder(); Iterator<String> it = columnNames.iterator(); while (it.hasNext()) { final String columnName = it.next(); names.append(columnName); values.append(':').append(columnName); if (it.hasNext()) { names.append(','); values.append(','); } } return "INSERT INTO " + tableName + " (" + names + ") VALUES (" + values + ")"; } }