java程序里怎么将包涵 's 的字符串插入到数据表中?
我程序里这样处理的String re="abc's";
String str=re.replaceAll("'","\'");但是现在还是不能把str插入到数据表中,请教大家解决办法?
我程序里这样处理的String re="abc's";
String str=re.replaceAll("'","\'");但是现在还是不能把str插入到数据表中,请教大家解决办法?
解决方案 »
- java调用script如何在页面上显示啊
- struts和servlet能同时用不啊
- cas spring security3整合爆错
- 快来看看.
- session的存活时间(学java se一定要进来看一看)
- 问几个spring的面试问题
- hibernate 单向多对一 问题,请高手指教
- MyEclipse开发Struts时用到网页框架遇到问题,求助!!!
- ******紧急求助******JDBC在获取数据库字段类型后怎么区分整型与浮点类型!
- 修饰浮的private和protected一起用的问题
- spring+struts+hibernate整合需要下载什么东西?
- jfreechart图可以当做applet嵌入jsp中吗?
public String c;
//在a的I处插入B
public String insert(String a,String b,int i){
c = a.substring(0, i) + b + a.substring(i,a.length());
return c;
}
public static void main(String args[]){
String a = "asdfgh";
String b = ",r";
int i = 3;
Test test = new Test();
System.out.println(test.insert(a, b, i));
} }
public String c;
//在a的I处插入B
public String insert(String a,String b,int i){
c = a.substring(0, i) + b + a.substring(i,a.length());
return c;
}
public static void main(String args[]){
String a = "asdfgh";
String b = "',)*!r";
int i = 3;
Test test = new Test();
System.out.println(test.insert(a, b, i));
} }
结果
asd',)*!rfgh
还要什么符号都可以加
这个在java层面是没问题的啊,不用转义,
但是在sql里面就需要转义
String str="abc''s";
直接把str插入到数据库试试看。
在数据库中"abc's"也不用转义,
我用的是mysql
比如insert into t values('dd''');
插入的是"dd'"
正解为:
String re="abc's";
String str=re.replaceAll("'","''"); 这样就可以直接插入到sqlserver中了