sql语句插入的数据中含有单引号怎么办.docx

上传人:b****0 文档编号:18251521 上传时间:2023-08-14 格式:DOCX 页数:17 大小:20.19KB
下载 相关 举报
sql语句插入的数据中含有单引号怎么办.docx_第1页
第1页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第2页
第2页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第3页
第3页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第4页
第4页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第5页
第5页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第6页
第6页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第7页
第7页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第8页
第8页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第9页
第9页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第10页
第10页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第11页
第11页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第12页
第12页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第13页
第13页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第14页
第14页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第15页
第15页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第16页
第16页 / 共17页
sql语句插入的数据中含有单引号怎么办.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

sql语句插入的数据中含有单引号怎么办.docx

《sql语句插入的数据中含有单引号怎么办.docx》由会员分享,可在线阅读,更多相关《sql语句插入的数据中含有单引号怎么办.docx(17页珍藏版)》请在冰点文库上搜索。

sql语句插入的数据中含有单引号怎么办.docx

sql语句插入的数据中含有单引号怎么办

 sql语句插入的数据中含有单引号怎么办?

收藏

新一篇:

 子类父类方法与属性的调用

(1) | 旧一篇:

 java中判断socket网络远端是否断开连接

sql语句插入的数据中含有单引号怎么办?

2001:

8:

17 

sql语句插入的数据中含有单引号怎么办?

sql中,insertintoyourTable(f1,f2)values(100,'abc')

字符串数据是用单引号包在外面的,如果插入的数据中包含单引号,就需要处理,你可以将单引号替换成两个单引号,在sql中连续两个单引号就表示一个单引号字符,例如

insertintoyourTable(f1,f2)values(100,'ab''c')表示插入

新记录f2字段为ab'c

使用函数replace可以实现这个功能:

replace(yourStr,"'","''")

 子类父类方法与属性的调用

(1)收藏

新一篇:

 子类父类方法与属性的调用

(2).txt | 旧一篇:

 sql语句插入的数据中含有单引号怎么办?

packagecom.me;

publicclassBookextendsBooks{

 Stringname="subname";

 Stringauthor;

 //show方法的重载

   publicvoidshow(Strings){

  System.out.println("subshow");

 }

 //show1方法的重写,不是重载

 publicvoidshow1(){

  System.out.println("subshow1");

 }   

 publicvoidshow3(){

  System.out.println("subshow3");

 }

 publicstaticvoidmain(Stringargs[]){

  Booksbs=newBook();

  //属性调用父类,方法调用子类(虚方法调用)

  {System.out.println(bs.name);

  bs.show1();

  }

  //执行时父类show方法中的this.show1()指代子类中的show1方法

  System.out.println("***********");

  {bs.show();                                     

  }

  //bs能访问super中的所有方法

  System.out.println("***********");

  {

   bs.show2();

  }

  System.out.println("***********");

  //bs无法访问Book类中的show3方法,若父类中有相同show3方法(有相同的方法名和参数)则

  //会访问子类中的方法,这就是前面所说的方法调用子类子类

  {

   //bs.show3();出错

  }

  //查看bs是否是Book类的实例,若是则强制类型转化后就可以访问子类中的所有方法

  if(bsinstanceofBook){

   Bookbook=(Book)bs;

   book.show3();

  }

 }

}

扩展:

Books为一接口而Book为实现这一接口的类,访问name时

访问的还是接口中的值(supername)

 

 

packagecom.me;

classBooks{

Stringname="supername";

Stringauthor;

publicvoidshow(){

 System.out.println("supershow");

   this.show1();

}

publicvoidshow1(){

 System.out.println("supershow1");

}

publicvoidshow2(){

 System.out.println("supershow2");

}

publicvoidshow3(Strings){

 System.out.println("supershow3");

}

}

 

supername

subshow1

***********

supershow

subshow1

***********

supershow2

***********

subshow3

 子类父类方法与属性的调用

(2).txt收藏

新一篇:

 子类父类方法与属性的调用(3) | 旧一篇:

 子类父类方法与属性的调用

(1)

 publicclassBooks{

Stringname="supername";

staticStringage="superage";

publicBooks(){

 System.out.println("super构造方法");

 System.out.println(this.name);

(1) System.out.println(name);           //以上两句均会打印"supername"

 System.out.println(age);       

 

}

publicstaticvoidshow(){

 System.out.println("superstaticshow");

 System.out.println(age);

}

publicvoidshow1(){

 System.out.println("supercommonshow1");

 System.out.println(this.name);

 System.out.println(name);

 System.out.println(this.age);

 System.out.println(age);

}

}

 

publicclassBookextendsBooks{

 Stringname="subname";

 staticStringage="subage";

 publicBook(){

  System.out.println("sub构造方法");

  System.out.println(this.name);

(2)  System.out.println(name);     //以上两句均会打印"subname"

  System.out.println(age);

  

 }

 publicstaticvoidshow(){

  System.out.println("subshow");

  System.out.println(age);

 }

 publicvoidshow1(){

  System.out.println("subcommonshow1");

  System.out.println(this.name);

  System.out.println(name);

  System.out.println(this.age);

  System.out.println(age);

 }

 publicstaticvoidmain(Stringargs[]){

  System.out.println("bs构造方法:

");

  Booksbs=newBook();                  //先执行父类的构造方法再执行子类的构造方法

  System.out.println("bs的staticshow:

");

  bs.show();

  System.out.println("bs的commonshow1:

");

  bs.show1();

(3)  System.out.println(bs.name);

(5)            System.out.println(bs.age);

  System.out.println("b的构造方法");

  Bookb=newBook();

  System.out.println("b的staticshow:

");

  b.show();

  System.out.println("b的commonshow1:

");

  b.show1();

(4)  System.out.println(b.name);  

(6)  System.out.println(b.age);

 }

}

执行结果

bs构造方法:

super构造方法

supername

supername

superage

sub构造方法

subname

subname

subage

bs的staticshow:

superstaticshow

superage

bs的commonshow1:

subcommonshow1

subname

subname

subage

subage

supername (3)

superage  (5)

b的构造方法

super构造方法

supername

supername

superage

sub构造方法

subname

subname

subage

b的staticshow:

subshow

subage

b的commonshow1:

subcommonshow1

subname

subname

subage

subage

subname (4)

subage  (6)

总结:

1.在执行子类的构造方法前先执行父类的构造方法

2.子类和父类中都有属性name时

     注意

(1)

(2)(3)(4)

(1)

(2)中在方法中直接打印name,this.name时会直接打印本类中的name属性值,但如(3)(4)中

        Booksbs=newBook();

        Bookb=newBook();

(3)中打印的是父类的name属性值(这就是前面所说过的属性调用父类,方法调用子类),

(4)中打印的是子类中的name属性值

      这两种情况一定要弄清楚

3.前面说过Booksbs=newBook();时属性调用父类,方法调用子类但是当属性,方法都声明为静态时如子类父类中的类属性age,类方法show时this.name,this.show所指的就是this.name,this.show所在类的类属性和类方法

4.Booksbs=newBook();

 只有bs.name的时候才会打印父类中的name属性值,其他在方法中使用this.name(或name)打印的都是本类中的name值。

this.show1时执行的是子类中的方法,假若子类中没有show1方法则会执行父类中的show1方法

5.Booksbs=newBook();

此时Books,Book两者的构造函数都会执行,并不仅仅执行Books的构造函数。

6.Booksbs=newBook();

 bs.name(父类的name)

 bs.show1(子类的show1)

 (父类中)this.show(父类的show)

 (子类中)this.show(子类的show)

 (父类中)this.show1(子类的show1)

 Bookb=newBook();

 b.name (子类的name)

 b.show1(子类的show1)

 子类父类方法与属性的调用(3)收藏

新一篇:

 子类父类方法与属性的调用(4) | 旧一篇:

 子类父类方法与属性的调用

(2).txt

 packagecom.me;

publicclassBooks{

Stringname="supername";

staticStringage="superage";

publicBooks(){

 System.out.println("super构造方法");

 System.out.println(this.name);

 System.out.println(name);

 System.out.println(age);

 System.out.println("^^^^^^^^^^^^^^^^^^^^^^^");

(1) this.show1();

 

}

publicvoidshow1(){

 System.out.println("supercommonshow1"); 

 System.out.println(this.name);

 System.out.println(name);

 System.out.println(this.age);

 System.out.println(age);

}

}

packagecom.me;

publicclassBookextendsBooks{

 Stringname="subname";

 staticStringage="subage";

(3) publicBook(){

  System.out.println("sub构造方法");

  System.out.println(this.name);

  System.out.println(name);

  System.out.println(age);

  System.out.println("book构造方法内@@@@@@@@@@@");

(2)  this.show1();

  

 }

 publicvoidshow1(){

  System.out.println("subcommonshow1");

  System.out.println(this.name);

  System.out.println(name);

  System.out.println(this.age);

  System.out.println(age);

 }

 publicstaticvoidmain(Stringargs[]){

  System.out.println("bs构造方法:

");

  Booksbs=newBook();

  System.out.println("bs构造方法结束");

  System.out.println();

  System.out.println("b的构造方法");

  Bookb=newBook();

  System.out.println("b的构造方法结束");

  

  

 }

}

结果:

bs构造方法:

super构造方法

supername

supername

superage

^^^^^^^^^^^^^^^^^^^^^^^

subcommonshow1

null

null

subage

subage

sub构造方法

subname

subname

subage

book构造方法内@@@@@@@@@@@

subcommonshow1

subname

subname

subage

subage

bs构造方法结束

b的构造方法

super构造方法

supername

supername

superage

^^^^^^^^^^^^^^^^^^^^^^^

subcommonshow1

(4)null

(5)null

subage

subage

sub构造方法

subname

subname

subage

book构造方法内@@@@@@@@@@@

subcommonshow1

subname

subname

subage

subage

b的构造方法结束

总结:

Booksbs=newBook();

当执行到父类的构造方法

(1)处时调用子类的show1;

show1方法里name打印的是null,此时还未执行子类的

构造方法,子类中的成员变量name还未初始化因此

此时打印的是null,但类变量age可以正确打印subage,

当执行完show1后再去初始化子类此时执行

(2)时可正

确打印name,age

Bookb=newBook();

和上面的分析差不多,但是我们现在要思考的是我们在同一个类

中先定义了一个bs(Booksbs=newBook();)对象,初始化过程中

name变量应该已经初始化了,但是(4)(5)处打印的还是null,这是

为什么呢?

我认为子类中的name是局部变量,当创建b的时候重新

进行还是先从父类再到子类,子类调用show1时子类还未初始化变量

name没有赋值,b的创建和bs的创建完全独立,每新建一个对象局部

变量都会重新初始化,重新分配内存空间因此为null

 子类父类方法与属性的调用(4)收藏

新一篇:

 语句块与构造方法的执行顺序 | 旧一篇:

 子类父类方法与属性的调用(3)

 packagecom.me;

publicclassParent{

 publicStringname="parentname";

 {

  System.out.println("parentcommon语句块");

 }

 static{

    System.out.println("parentstatic语句块"); 

 }

 publicParent(){

  System.out.println(this.name);

  this.show();

 }

 publicvoidshow(){

  System.out.println("here "+this.name);

  System.out.println("Parentcommonshow");

 }

}

packagecom.me;

publicclassChildAextendsParent{

   publicstaticStringname="CA";

 static{

    System.out.println("childastatic语句块"); 

 }

 {

  System.out.println("childacommon语句块");

 }

   publicChildA(){

    

    System.out.println(this.name);

    this.show();

   }

   publicvoidshow(){

    System.out.println("childAcommonshow");

   }

}

packagecom.me;

publicclassChildBextendsChildA{

 publicStringname="CB";

 publicCc=newC();

 static{

     System.out.println("childbstatic语句块"); 

  }

  {

   System.out.println("childbcommon语句块");

  }

  

 publicChildB(){

     System.out.println(this.name);

     this.show();

     Dd=newD();

    }

 

 publicvoidshow(){

     System.out.println("childBcommonshow");

     

 }

 

 

}

packagecom.me;

publicclassC{

 publicStringname="C"; 

   publicC(){

    System.out.println(this.name);

   }

}

packagecom.me;

publicclassD{

 publicStringname="D";

   publicD(){

    System.out.println(this.name);

   }

}

packagecom.me;

publicclassTest{ 

 publicstaticvoidmain(String[]args){

    ChildBcb=newChildB();    

   }

}

一共六个类parent,childa,childb,c,d,test

publicclassChildAextendsParent

publicclassChildBextendsChildA

c,d,test独立

ChildB的属性中publicCc=newC();

ChildB的构造方法中Dd=newD();

好了,明白了类之间的关系就写出打印结果了,如下:

parentstatic语句块

childastatic语句块

childbstatic语句块

parentcommon语句块

parentname

childBcommonshow

childacommon语句块

CA

childBcommonshow

C

childbcommon语句块

CB

childBcommonshow

D

总结:

执行的顺序

父类------>子类

各个类中的静态语句块(匿名方法)

普通(非静态)语句块,属性的初始化都在构造方法前执行

普通(非静态)语句块,属性按顺序由上到下一次执行

Parent类,ChildA,ChildB存在继承关系,并且三个类中都有

方法show,this.show执行的始终是子类中的show方法,若ChildB中

无show则执行ChildA中的show方法,若ChildB中也没有则执行Parent

中的方法,若ChildB中没有ChildA中有则执行Parent中的(废话,呵呵)

到此"子类父类方法与属性的调用"系列到此结束,不知坚持看完这四篇

文章的朋友晕了没,呵呵

睡觉去了。

 语句块与构造方法的执行顺序收藏

新一篇:

 子类构造函数必须先初始化父类 | 旧一篇:

 子类构造函数必须先初始化父类

 

publicclassTest{

 Stringname="John";

 Stringauthor;

 

 /*{

  System.out.println("语句块");

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2