mysql+特殊字符+输出_Mysql 特殊字符处置

mysql 特殊字符处理

import java.util.HashMap; import java.util.Map; /** * User: pdc738 Date: 06.22, 2010 Time: 3:36:20 PM * To Encoder special character. * If you want to insert binary data into a string column (such as a BLOB column), the following characters must be represented by escape sequences. NUL NUL byte (0x00). Represent this character by “/0” (a backslash followed by an ASCII “0” character). / Backslash (ASCII 92). Represent this character by “//”. ' Single quote (ASCII 39). Represent this character by “/'”. " Double quote (ASCII 34). Represent this character by “/"”. * Within a string, certain sequences have special meaning unless the NO_BACKSLASH_ESCAPES SQL mode is enabled. Each of these sequences begins with a backslash (“/”), known as the escape character. MySQL recognizes the following escape sequences in referencesMap */ public class MYSQLEncoder { private static Map referencesMap = new HashMap(); static{ referencesMap.put("'","//'"); referencesMap.put("/"","///""); referencesMap.put("//",""); referencesMap.put("/n","///n"); referencesMap.put("/0","///0"); referencesMap.put("/b","///b"); referencesMap.put("/r","///r"); referencesMap.put("/t","///t"); referencesMap.put("/f","///f"); } //escape sql tag with the source code. public static String encode(String source) { if (source == null) return ""; StringBuffer sbuffer = new StringBuffer(source.length()); for (int i = 0; i < source.length(); i++) { String c = source.substring(i,i+1); //System.out.println("c=" + c); //System.out.println(referencesMap.get(c)); if (referencesMap.get(c) != null) { sbuffer.append(referencesMap.get(c)); } else { sbuffer.append(c); } } return sbuffer.toString(); } public static void main(String[] args){ String tt = encode("They'are /"ok/". //a"); System.out.print(tt); } }

欢迎大家阅读《Mysql 特殊字符处置》,跪求各位点评,by 搞代码

原创文章,转载请注明: 转载自搞代码

e7ce419cf2d6ad34d01da2ceb8829eed.png

微信 赏一包辣条吧~

023a57327877fb4402bcc76911ec18ea.png

支付宝 赏一听可乐吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值