The execute method executes an SQL statement and indicates the form of the first result. You must then use the methods getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s).
boolean execute() Returns: true if the first result is a ResultSet object; false if the first result is an update count or there is no result
它的返回值是 boolean,
true就成功,failse就失败。
Returns:
true if the first result is a ResultSet object; false if the first result is an update count or there is no result
try退出返回true
catch退出返回false
一楼的,execute();是不对的,我试过,可以插入数据数据,但是也是false,如果返回的是执行返回的是resultset结果,执行成则是 true,如果为计数性的查询,或者无结果返回的执行成功也是false
throws SQLException 执行给定的 SQL 语句,该语句可能返回多个结果。在某些(不常见)情形下,单个 SQL 语句可能返回多个结果集合和/或更新计数。这一点通常可以忽略,除非正在 (1) 执行已知可能返回多个结果的存储过程或者 (2) 动态执行未知 SQL 字符串。 execute 方法执行 SQL 语句并指示第一个结果的形式。然后,必须使用方法 getResultSet 或 getUpdateCount 来获取结果,使用 getMoreResults 来移动后续结果。 参数:
sql - 任何 SQL 语句
返回:
如果第一个结果为 ResultSet 对象,则返回 true;如果其为更新计数或者不存在任何结果,则返回 false
抛出:
SQLException - 如果发生数据库访问错误,或者在已关闭的 Statement 上调用此方法
查询用executeQuery()-返回得到了结果集则成功,并不是结果集为空。若不成功则出错