文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>实用代码整理[原创]

实用代码整理[原创]

时间:2010-06-01  来源:hkebao

1、动态拼结SQL。依据IP查询结果集

package cn.test;
public class Test {
    public static void main(String[] args) {
        String ips = "19.2.128.*;124.225.*.32;124.225.65.30";
        String[] results = ips.split(";");
        String dysqlString = "";
        StringBuffer tmp = new StringBuffer();
        int k = 0;
        for (String string : results) {
            if (k == results.length - 1) {
                if (string.contains("*")) {
                    int position = string.indexOf("*");
                    tmp.append("(left(localip,"+(position-1)+") = '" + string.substring(0, position-1) + "' or left(foreightip," + (position - 1)+") = '" + string.substring(0, position-1) +"') ");
                } else {
                    tmp.append("(localip='"+string.trim()+"' or foreigip='" + string.trim() + "') ");
                }
                break;
            }
            if (string.contains("*")) {
                int position = string.indexOf("*");
                tmp.append("(left(localip,"+(position-1)+") = '" + string.substring(0, position-1) + "' or left(foreightip," + (position - 1)+") = '" + string.substring(0, position-1) +"') or ");
            } else {
                tmp.append("(localip='"+string.trim()+"' or foreigip='" + string.trim() + "') or ");
            }
            k++;
        }
        dysqlString = tmp.toString();
        System.out.println(dysqlString);
    }
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载