sqltool.java

来自「企业进销存源码」· Java 代码 · 共 68 行

JAVA
68
字号
package com.web.util;

/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class SQLTool {
    public final static int NUMBER = 0;
    public final static int STRING = 1;
    public final static int DATE = 2;

    public static String getSelectWhereClause(
            int dataType,
            String srcSqlStr,
            String fieldName,
            String condition,
            String value) {
        StringBuffer buffer = new StringBuffer();

        if (value == null) return srcSqlStr;

        if (value.trim().length() > 0) {

            try {
                if (srcSqlStr == null) {

                    System.out.println("srcSqlStr can't be null!");

                }

            } catch (Exception ex) {
                ex.printStackTrace();
            }

            if (srcSqlStr.trim().length() != 0) {
                //srcSqlStr isn't empty string.
                buffer.append(srcSqlStr + " AND ");
            }

            switch (dataType) {
                case NUMBER:

                    break;
                case STRING:
                    if (condition.toLowerCase().equals("like")) {
                        buffer.append(
                                fieldName + " " + condition + " '%" + value + "%'");
                    } else {
                        buffer.append(
                                fieldName + " " + condition + " '" + value + "'");
                    }
                    break;
                case DATE:
                    break;
            }
            return buffer.toString();
        } else {
            return srcSqlStr;

        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?