zoukankan      html  css  js  c++  java
  • 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的综合.

    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 语句,且这个语句中不能带有 ? 占位符。
  • 相关阅读:
    HDU 2757 Ocean Currents
    HDU 2704 Bulletin Board
    HDU 2234 无题I
    HDU 3638 Go , SuSu
    HDU 1199 Color the Ball
    HDU 1430 魔板
    PL/SQL例外的介绍
    表分区介绍
    移动表空间数据文件
    long\lob\bfile类型介绍
  • 原文地址:https://www.cnblogs.com/lijiews/p/lj201312311005.html
Copyright © 2011-2022 走看看