提供若干方法,用于执行 SQL 查询以生成 ResultSet 对象,或用于对数据库执行准备的 SQL 语句。
public interface PreparedStatement
PreparedStatement 接口的所有成员,包括所有继承的成员。
名称 | 说明 |
---|---|
关闭 PreparedStatement,以释放与其相关的内存资源。 | |
执行准备的 SQL 语句。 | |
执行准备的 SQL SELECT 语句并返回 ResultSet 对象。 | |
返回 OutputStream 对象。 | |
返回 Writer 对象。 | |
返回由名称表示的值的序数(基数:1)。 | |
返回对 SQL 查询执行计划的基于文本的说明。 | |
返回对 SQL 查询执行计划的基于文本的说明,以树形结构显示。 | |
返回准备的 SQL 语句的 ResultSet 对象。 | |
返回自上一次执行语句之后插入、更新或删除的行数。 | |
确定 PreparedStatement 对象是否包含 ResultSet 对象。 | |
将值设置为 SQL 语句中的主机变量。 | |
将空值设置为 SQL 语句中的主机变量。 |
以下示例演示了如何创建 PreparedStatement 对象,如何检查 SELECT 语句执行过程是否创建了 ResultSet 对象,如何将任何 ResultSet 对象保存到局部变量,以及之后如何关闭 PreparedStatement:
// Create a new PreparedStatement object from an existing connection. String sql_string = "SELECT * FROM SampleTable"; PreparedStatement ps = conn.prepareStatement(sql_string); // Result returns true if the statement runs successfully. boolean result = ps.execute(); // Check if the PreparedStatement object contains a ResultSet object. if (ps.hasResultSet()) { // Store the ResultSet in the rs variable. ResultSet rs = ps.getResultSet; } // Close the PreparedStatement object to release resources. ps.close(); |
如果语句中包含表达式,则只要列名称出现,它便会包含主机变量。主机变量被输入为 '?' 字符(未命名的主机变量)或 ":name"(已命名的主机变量)。
在以下示例中,有两种主机变量可使用为所讨论的 SQL 语句准备的 PreparedStatement 对象进行设置。
SELECT * FROM SampleTable WHERE pk > :bound AND pk < ? |
close 方法
execute 方法
executeQuery 方法
getBlobOutputStream 方法
getClobWriter 方法
getOrdinal 方法
getPlan 方法
getPlanTree 方法
getResultSet 方法
getUpdateCount 方法
hasResultSet 方法
set 方法
setNull 方法
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |