Statement、PreparedStatement和callableStatement的异同
来源:互联网 发布:怎么看淘宝访客数据 编辑:程序博客网 时间:2024/06/05 09:31
1.Statement、PreparedStatement和CallableStatement都是接口(interface)。
2.Statement继承自Wrapper、PreparedStatement继承自Statement、CallableStatement继承自PreparedStatement。
3.
Statement接口提供了执行语句和获取结果的基本方法;
PreparedStatement接口添加了处理 IN 参数的方法;
CallableStatement接口添加了处理 OUT 参数的方法。
4.
a.Statement:
普通的不带参的查询SQL;支持批量更新,批量删除;
b.PreparedStatement:
可变参数的SQL,编译一次,执行多次,效率高;
安全性好,有效防止Sql注入等问题;
支持批量更新,批量删除;
c.CallableStatement:
继承自PreparedStatement,支持带参数的SQL操作;
支持调用存储过程,提供了对输出和输入/输出参数(INOUT)的支持;
Statement每次执行sql语句,数据库都要执行sql语句的编译 ,
最好用于仅执行一次查询并返回结果的情形,效率高于PreparedStatement。
PreparedStatement是预编译的,使用PreparedStatement有几个好处
1. 在执行可变参数的一条SQL时,PreparedStatement比Statement的效率高,因为DBMS预编译一条SQL当然会比多次编译一条SQL的效率要高。
2. 安全性好,有效防止Sql注入等问题。
3. 对于多次重复执行的语句,使用PreparedStament效率会更高一点,并且在这种情况下也比较适合使用batch;
4. 代码的可读性和可维护性。
0 0
- 说说Statement、PreparedStatement和CallableStatement的异同
- Statement、PreparedStatement和callableStatement的异同
- Statement、PreparedStatement和CallableStatement异同
- Statement、PreparedStatement和CallableStatement异同
- Statement、PreparedStatement和CallableStatement
- Statement、PreparedStatement和CallableStatement
- Statement、PreparedStatement和CallableStatement
- Statement,PreparedStatement,CallableStatement 的联系和区别
- JDBC: Statement、PreparedStatement和CallableStatement
- Statement、PreparedStatement和CallableStatement区别
- JDBC--Statement、PreparedStatement和CallableStatement
- Statement、PreparedStatement和CallableStatement区别
- Statement、CallableStatement、preparedStatement的区别
- Statement、PreparedStatement、CallableStatement的作用
- PreparedStatement、CallableStatement、Statement的区别
- jdbc中Statement、PreparedStatement和CallableStatement的区别
- JDBC中Statement,PreparedStatement和CallableStatement的比较
- JDBC中Statement、PreparedStatement和CallableStatement的使用
- 读书笔记(1)
- mycncart 1.4.0.0 新版本发布
- CodeForces 598A--Tricky Sum
- Java中基于TCP的Socket通信
- HDU 2973 YAPTCHA [威尔逊定理]
- Statement、PreparedStatement和callableStatement的异同
- 文章标题
- HDU 1257:最少拦截系统
- epoll模型的EPOLLLT模式和EPOLLET模式比较
- 决策树个人理解
- 详解spring mvc 3.0常用注解
- springMVC-2
- leetcode:Rotate Image 【Java】
- IDA入门(1)