execute,executeUpdate,executeQuery返回值的区别

execute,executeUpdate,executeQuery返回值的区别
昨天发现了个很有意思的问题,执行插入的sql,sql执行成功,数据成功插入,
但是execute返回的结果一直为false,所以差了点资料,看了看源码,找到问题,
写个随笔分享一下,希望对大家有帮助

execute返回结果为boolean类型
源码:
* @return <code>true</code> if the first result is a <code>ResultSet</code>
* object; <code>false</code> if the first result is an update
* count or there is no result
如果返回一个ResultSet结果集,则返回true,如果是更新或者插入返回false,所以即使用
execute,也不能判断是否插入成功,不过可以用来判断是查询或者更新。

executeQuery返回ResultSet类型
* @return a <code>ResultSet</code> object that contains the data produced by the
* query; never <code>null</code>
用于执行select语句。

executeUpdate返回int类型
* @return either (1) the row count for SQL Data Manipulation Language (DML) statements
* or (2) 0 for SQL statements that return nothing
用于执行INSERT、UPDATE 或 DELETE 语句,
效果是修改表中零行或多行中的一列或多列,返回更新的行数

原文地址:https://www.cnblogs.com/cunmo/p/11356332.html

时间: 2024-07-29 04:44:11

execute,executeUpdate,executeQuery返回值的区别的相关文章

函数指针与指针函数返回值的区别

指针函数是指带指针的函数,即本质是一个函数.函数返回类型是某一类型的指针定义: 类型标识符 *函数名(参数表)eg: int *f(x,y);函数指针是指向函数的指针变量,即本质是一个指针变量.int (*f) (int x); /* 声明一个函数指针 */ f=func; /* 将func函数的首地址赋给指针f */ 函数指针与指针函数返回值的区别,码迷,mamicode.com

指针作为形参和返回值的区别

关于指作为针形参与返回值的常见问题 1.返回栈中局部变量的地址 #include <stdio.h> int *fun(){ int a = 10; // a为当前方法栈中的局部变量,结束即释放 return &a; // 所以传递出去的会是一个无效(非法)地址 } int main(int argc, char const *argv[]) { int *a = NULL; a = fun(); *a = 100; // error,操作非法内存 printf("a = %

测试函数用Return 返回值和用函数名返回值的区别

'*************************************************************************'**模 块 名:工程1 - Form1'**说    明:蓝凤凰设计商城 浴火凤凰-郭卫 | 蓝凤凰-魔灵 | 郭卫-icecept'**创 建 人:浴火凤凰-郭卫'**日    期:2015年10月19日  21:53:17'**修 改 人:浴火凤凰-郭卫'**日    期:'**描    述:QQ:493405998 | 微信\旺旺:icece

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

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

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

在用纯JSP做一个页面报警功能的时候习惯性的用executeQuery来执行SQL语句,结果执行update时就遇到问题,语句能执行,但返回结果出现问题,另外还忽略了executeUpdate的返回值不是结果集ResultSet,而是数值!特收藏如下一篇文章: JDBCTM中Statement接口提供的execute.executeQuery和executeUpdate之间的区别 Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和

转载----execute、executeQuery和executeUpdate之间的区别

JDBCTM中Statement接口提供的execute.executeQuery和executeUpdate之间的区别 Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 方法executeQuery 用于产生单个结果集的语句,例如 SELECT 语句. 被使用最多的执行 SQL 语句的方法是 executeQuery.这个方法被用来执行 SELECT 语句,它几

JDBC中PreparedStatement接口提供的execute、executeQuery和executeUpdate之间的区别及用法

JDBC中PreparedStatement接口提供的execute.executeQuery和executeUpdate之间的区别及用法 (2012-08-27 09:36:18) 转载▼ 标签: statement execute executequery executeupdate 杂谈 分类: DataBase区 PreparedStatement接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语

execute、executeQuery和executeUpdate之间的区别

execute.executeQuery和executeUpdate之间的区别 博客分类: SQL SQL JDBCTM中Statement接口提供的execute.executeQuery和executeUpdate之间的区别 Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 方法executeQuery        用于产生单个结果集的语句,例如 SELEC

execute、executeQuery和executeUpdate之间的区别 转

转:http://blog.csdn.net/colin_fantasy/article/details/3898070 execute.executeQuery和executeUpdate之间的区别 JDBC中Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 1>方法executeQuery 用于产生单个结果集(ResultSet)的语句,例如 SELECT 语