1. ResultSet executeQuery(String sql); 执行SQL查询,并返回ResultSet 对象。
 2.int executeUpdate(String sql); 可执行增,删,改,返回执行受到影响的行数。
 3. boolean execute(String sql); 可执行任何SQL语句,返回一个布尔值,表示是否返回ResultSet 。

execute是executeQuery和executeUpdate的综合.

-----

executeUpdate() 这是 PreparedStatement 接口中的方法
executeUpdate(String sql) 这是 PreparedStatement 从父接口 Statement 中继承过来的方法

executeUpdate() 中执行 SQL 语句需要在创建 PerparedStatement 时通过 Connection 的 prepareStatement(String sql) 方法中写出,因为 PerparedStatement 中的 SQL 语句数据库需要进行预编译和缓存,因此要在创建 PerparedStatement 对象时给出 SQL 语句。

而 executeUpdate(String sql) 是 Statement 中的方法,参数中的 SQL 语句只是提交给数据库去执行,并不需要预编译。

如果 SQL 语句中有 ? 占位符,那么在设置好占位符中的值后,必须使用 executeUpdate() 执行。而 executeUpdate(String sql) 只是提交一个 SQL 语句,且这个语句中不能带有 ? 占位符。

 

【转载】execute、executeUpdate、executeQuery三者的区别(及返回值)的更多相关文章

  1. execute、executeUpdate、executeQuery三者的区别及返回值

    一.boolean execute(String sql)允许执行查询语句.更新语句.DDL语句.返回值为true时,表示执行的是查询语句,可以通过getResultSet方法获取结果:返回值为fal ...

  2. execute、executeUpdate、executeQuery三者的区别(及返回值)

    1. ResultSet executeQuery(String sql); 执行SQL查询,并返回ResultSet 对象. 2.int executeUpdate(String sql); 可执行 ...

  3. executeUpdate,executeQuery,executeBatch 的区别

    executeQuery : 用于实现单个结果集,例如: Select 一般使用executeQuery 就是来实现单个结果集的工具 executeUpdate 用于执行 INSERT.UPDATE ...

  4. ExecutorService.execute(Runnable x) 判断是否完成,得到返回值

    public class RunnableTestMain { public static void main(String[] args) { ExecutorService pool = Exec ...

  5. SQL中的左连接与右连接有什么区别,点解返回值会不同?(转)

    例子,相信你一看就明白,不需要多说 A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 95 01 张三 02 语文 90 02 李四 03 英语 80 04 王五 ...

  6. mysql 中execute、executeQuery和executeUpdate之间的区别

    在用纯JSP做一个页面报警功能的时候习惯性的用executeQuery来执行SQL语句,结果执行update时就遇到问题,语句能执行,但返回结果出现问题,另外还忽略了executeUpdate的返回值 ...

  7. execute、executeQuery和executeUpdate之间的区别

    JDBCTM中Statement接口提供的execute.executeQuery和executeUpdate之间的区别 Statement 接口提供了三种执行 SQL 语句的方法:executeQu ...

  8. JDBC中execute、executeQuery和executeUpdate的区别

    Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 1>方法e ...

  9. java execute、executeQuery和executeUpdate之间的区别

    在用纯JSP做一个页面报警功能的时候习惯性的用executeQuery来执行SQL语句,结果执行update时就遇到问题,语句能执行,但返回结果出现问题,另外还忽略了executeUpdate的返回值 ...

随机推荐

  1. vsftpd的安装和配置

    1  安装vsftpd sudo apt-get install vsftpd 2  测试是否安装成功 sudo service vsftpd restart 如果有反应即成功 3  彻底卸载vsft ...

  2. R的数据结构--矩阵

    矩阵:存放相同类型元素的二维向量 参数解释 matrix(data=NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) 参数含义如下: da ...

  3. duilib学习领悟(1)

    学习duilib已经有一段时间,一直没时间写总结,今天得出空来,写写心得体会! 由于本人知识有限,若有错误地方,望批评指正.多谢.! 初识duilib 刚开始接触duilib的时候,觉的他好神奇,整个 ...

  4. SARS病毒 (生成函数 + 快速幂)

    链接:https://ac.nowcoder.com/acm/contest/992/A来源:牛客网 题目描述 目前,SARS 病毒的研究在世界范围内进行,经科学家研究发现,该病毒及其变种的 DNA ...

  5. C#新增按钮

    代码亲测可用,似乎不需要“ADD”,如下:form_load段:for (int i = 0; i < 10; i++){btn = new Button();btn.Parent = this ...

  6. Java中的集合List、ArrayList、Vector、Stack(三)

    List接口 List集合代表一个有序集合,集合中每一个元素都有其对应的顺序索引.List集合容许使用重复元素,可以通过索引来访问指定位置的集合对象. ArrayList和Vector实现类 Arra ...

  7. Go学习笔记(六) | 使用swaggo自动生成Restful API文档(转)

    关于Swaggo 或许你使用过Swagger, 而 swaggo就是代替了你手动编写yaml的部分.只要通过一个命令就可以将注释转换成文档,这让我们可以更加专注于代码. 目前swaggo主要实现了sw ...

  8. PHP处理base64编码字符串

    接收前端传过来的base64编码后的字符串, 如果是json字符串, 那么PHP使用file_get_contents('php://input'); 来接收. 本次这里是以post传参的形式传bas ...

  9. [Cogs] 线型网络

    题面 http://cogs.pro:8080/cogs/problem/problem.php?pid=6 题解 https://www.zybuluo.com/wsndy-xx/note/1135 ...

  10. ubuntu彻底卸载mysql并且重新安装

    环境: root@ubuntu:/usr/local/mysql/data# uname -a Linux ubuntu 4.4.0-87-generic #110-Ubuntu SMP Tue Ju ...