当前位置:   article > 正文

Statement详细理解_statement.executequery

statement.executequery

1、创建Statement对象

Statement对象用Connection的方法createStatement创建,代码如下:

  1. Connection connection = DriverManager.getConnection(url,user,password);
  2. Statement statement = connection.createStatement();

为了执行Statement对象,被发送到数据库的sql语句将被作为参数提供给Statement方法:

 ResultSet resultSet = statement.executeQuery("select * from student");

2、使用Statement对象执行语句:

  Statement接口提供了三种执行sql语句的方法:executeQuery、executeUpdate和execute。

executeQuery:

用于产生单个结果集语句,例如select语句。在检索完ResultSet对象的所有行时该语句完成。

executeUpdate:

用于执行insert、update或delete语句以及aqlddl(数据定义语言)语句。当它执行时就完成了。

execute:

用于执行返回多个结果集、多个更新计数或者二者组合的语句。在检索所有结果集或它生成的更新计数之后语句才完成。

Statement概述

Statement对象用于将sql语句发送到数据库中。

实际上有三种Statement对象,它们都作为在连接上执行sql语句的包容器,他们都专用于发送特定类型sql语句:

Statement对象用于执行不带参数的简单sql语句;

PreparedStatement对象用于执行带或不带IN参数的预编译sql语句;

CallableStatement对象用于执行对数据库已存储过程的调用。

Statement接口提供了执行语句和获取结果的基本方法;

PreparedStatement接口添加了处理IN参数的方法;

CallableStatement添加了处理OUT参数的方法。

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/311403
推荐阅读
相关标签
  

闽ICP备14008679号