Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30479328
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: Java

2010-04-07 09:50:07

    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();
    }


阅读(2802) | 评论(0) | 转发(0) |
0

上一篇:P6spy属性文件

下一篇:简单ORM实现

给主人留下些什么吧!~~