文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>替换PreparedStatement中参数的方法

替换PreparedStatement中参数的方法

时间:2010-04-07  来源:qbq

    private String getQueryFromPreparedStatement(String sql, Object... args) {
        int len = sql.length();
        StringBuffer t = new StringBuffer(len * 2);
        
        if (args != null) {
            int i = 0, limit = 0, base = 0;
            
            while ((limit = sql.indexOf('?',limit)) != -1) {
                if (args[i] != null) {
                    t.append(sql.substring(base,limit));
                    t.append("'");
                    t.append(args[i].toString());
                    t.append("'");
                } else {
                    t.append(sql.substring(base,limit));
                    t.append(args[i]);
                }
                i++;
                limit++;
                base = limit;
            }
            if (base < len) {
                t.append(sql.substring(base));
            }
        }
        
        return t.toString();
    }


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

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载