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 语句,且这个语句中不能带有 ? 占位符。
  • 相关阅读:
    heapq of python
    array of python
    Unittest of Python
    事件驱动型工作流 vs 引擎型工作流
    airflow
    WPF 调试触发器
    WPF 使用Popup和TreeView实现树状下拉框
    Oracle : ORA 00933: SQL command not properly ended
    PostgreSQL && PostGIS
    基于ArcGIS开发3D立方体空间关系判断
  • 原文地址:https://www.cnblogs.com/lijiews/p/lj201312311005.html
Copyright © 2011-2022 走看看