zoukankan      html  css  js  c++  java
  • 【原创随笔】MySQL查询特殊字符转义

    package com.jeecms.cms.dao.assist.impl;

    import org.apache.commons.lang.IllegalClassException;

    public class SqlEscape {
    /**
    * 支持String,Integer,Character,Float,Double
    *
    @param obj
    *
    @return
    */
    public static String escape(Object obj){
    if (obj instanceof String||obj instanceof Integer || obj instanceof Character || obj instanceof Float || obj instanceof Double) {
    String text = obj.toString();
    StringBuffer sbf=new StringBuffer();
    for (int i = 0; i < text.toCharArray().length; i++) {
    sbf.append("\\").append(text.charAt(i));
    }
    return sbf.toString();
    }else{
    throw new IllegalClassException(String.class,obj);
    }
    }
    }

    新手,大神勿喷,有好的意见请回复!

    Author:Pale Life
    From: 
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    win2008服务器信任问题
    切换cmd的目录
    c#后的完整cookie
    c#网络编程-第一章
    c#访问mysql数据库
    标准库hashlib模块
    标准库ConfigParser模块
    标准库shutil
    标准库 xml
    标准库shelve
  • 原文地址:https://www.cnblogs.com/live365wang/p/2311647.html
Copyright © 2011-2022 走看看