java程序里怎么将包涵 's 的字符串插入到数据表中?
我程序里这样处理的String re="abc's";
String str=re.replaceAll("'","\'");但是现在还是不能把str插入到数据表中,请教大家解决办法?

解决方案 »

  1.   

    public class Test {
    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));


    } }
      

  2.   

    public class Test {
    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
    还要什么符号都可以加
      

  3.   

    String re="abc's"; 
    这个在java层面是没问题的啊,不用转义,
    但是在sql里面就需要转义
    String str="abc''s"; 
    直接把str插入到数据库试试看。
      

  4.   

    在java里面"abc's"不用转义;
    在数据库中"abc's"也不用转义,
    我用的是mysql
      

  5.   

    sql语句中的转义符好像是'号吧
    比如insert into t values('dd''');
    插入的是"dd'"
      

  6.   

    感谢大家的抢答!!感谢7、8、9楼给了我提示,
    正解为:
    String re="abc's"; 
    String str=re.replaceAll("'","''"); 这样就可以直接插入到sqlserver中了
      

  7.   

    原来在oracle和sqlserver 中 字符串中的 ‘ 需要转义,mysql中的不需要啊。我用的是oracle