Statement&PreparedStatement&CallableStatement
来源:互联网 发布:网络远程教育可靠吗 编辑:程序博客网 时间:2024/05/28 18:45
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)的支持;
5.
Statement每次执行sql语句,数据库都要执行sql语句的编译, 最好用于仅执行一次查询并返回结果的情形,效率高于PreparedStatement。
PreparedStatement是预编译的,使用PreparedStatement有几个好处:
(1) 在执行可变参数的一条SQL时,PreparedStatement比Statement的效率高,因为DBMS预编译一条SQL当然会比多次编译一条SQL的效率要高。
(2) 安全性好,有效防止Sql注入等问题。
(3) 对于多次重复执行的语句,使用PreparedStament效率会更高一点,并且在这种情况下也比较适合使用batch;
(4) 代码的可读性和可维护性。
参考至:牛客网问题“下面有关jdbc statement的说法错误的是?”征程大神的解析
- Statement、PreparedStatement和CallableStatement
- statement preparedstatement CallableStatement
- PreparedStatement、Statement、CallableStatement
- Statement、PreparedStatement和CallableStatement
- Statement&PreparedStatement&CallableStatement
- Statement、PreparedStatement、CallableStatement
- Statement、PreparedStatement和CallableStatement
- JDBC: Statement、PreparedStatement和CallableStatement
- Statement、CallableStatement、preparedStatement的区别
- Statement、PreparedStatement和CallableStatement异同
- Statement、PreparedStatement和CallableStatement区别
- Statement、PreparedStatement、CallableStatement的作用
- JDBC--Statement、PreparedStatement和CallableStatement
- Statement、PreparedStatement和CallableStatement区别
- PreparedStatement、CallableStatement、Statement的区别
- mysql-2-Statement|PreparedStatement|CallableStatement
- Statement、PreparedStatement和CallableStatement异同
- JDBC——Connection,Statement,PreparedStatement,CallableStatement
- 1025. 反转链表
- jquery 关于event.target使用的几点说明介绍
- ac自动机与状态转移
- GO语言linux下环境变量
- HDU2577:How to Type 简单DP
- Statement&PreparedStatement&CallableStatement
- Linux系统--/proc/uptime文件中参数说明
- iOS 网络高级编程二:HTTP并没有那么简单
- ajax跨域jsonp的两种解决办法
- 事先规划RTL结构
- TCP协议用在python和wifi模块之间
- 可能与不可能的边界:P/NP问题趣史
- Python爬虫从入门到懵逼-1
- 如何让子元素居于父元素底部