All Downloads are FREE. Search and download functionalities are using the official Maven repository.

matrix.module.based.utils.SqlUtil Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package matrix.module.based.utils;

import java.util.Collection;

/**
 * @author wangcheng
 */
public class SqlUtil {
    /**
     * SQL占位符?号生成
     */
    public static String getSQLPlace(Integer count) {
        if (count != null && count > 0) {
            String result = "";
            for (int i = 0; i < count; i++) {
                result += "?,";
            }
            return result.substring(0, result.length() - 1);
        }
        return "";
    }

    /**
     * SQL打印
     */
    public static String getSQL(String sql, Object[] args) {
        if (args != null && args.length > 0) {
            for (Object arg : args) {
                sql = sql.replace("?", "'" + arg.toString() + "'");
            }
        }
        return sql;
    }

    public static String getSQL(String sql, Collection args) {
        if (args != null && args.size() > 0) {
            for (Object arg : args) {
                sql = sql.replace("?", "'" + arg.toString() + "'");
            }
        }
        return sql;
    }
}