Statement
Statement 接口提供了三种执行 SQL 语句的方法: executeQuery、 executeUpdate 和 execute。
方法 executeQuery 用于产生单个结果集的语句,例如 SELECT 语句。
方法 executeUpdate 用于执行 INSERT、 UPDATE 或 DELETE 语句以及 SQL DDL (数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。
方法 execute 用于执行返回多个ResultSet 对象、多个更新计数或二者组合的语句。
“%”匹配零个或多个字符,“_”则匹配一个字符
stmt.executeQuery("SELECT name FROM Identifiers WHERE Id LIKE `\_%' {escape `\'};
stmt.execute(queryStringWithUnknownResults);
while (true) {
int rowCount = stmt.getUpdateCount();
if (rowCount > 0) { // 它是更新计数
System.out.println("Rows changed = " + count);
stmt.getMoreResults();
continue;
}
if (rowCount == 0) { // DDL 命令或 0 个更新
System.out.println(" No rows changed or statement was DDL command");
stmt.getMoreResults();
continue;
}
// 执行到这里,证明有一个结果集
// 或没有其它结果
ResultSet rs = stmt.getResultSet;
if (rs != null) {
. . . // 使用元数据获得关于结果集列的信息
while ( rs
break; // 没有其它结果
Statement 接口提供了三种执行 SQL 语句的方法: executeQuery、 executeUpdate 和 execute。
方法 executeQuery 用于产生单个结果集的语句,例如 SELECT 语句。
方法 executeUpdate 用于执行 INSERT、 UPDATE 或 DELETE 语句以及 SQL DDL (数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。
方法 execute 用于执行返回多个ResultSet 对象、多个更新计数或二者组合的语句。
“%”匹配零个或多个字符,“_”则匹配一个字符
stmt.executeQuery("SELECT name FROM Identifiers WHERE Id LIKE `\_%' {escape `\'};
stmt.execute(queryStringWithUnknownResults);
while (true) {
int rowCount = stmt.getUpdateCount();
if (rowCount > 0) { // 它是更新计数
System.out.println("Rows changed = " + count);
stmt.getMoreResults();
continue;
}
if (rowCount == 0) { // DDL 命令或 0 个更新
System.out.println(" No rows changed or statement was DDL command");
stmt.getMoreResults();
continue;
}
// 执行到这里,证明有一个结果集
// 或没有其它结果
ResultSet rs = stmt.getResultSet;
if (rs != null) {
. . . // 使用元数据获得关于结果集列的信息
while ( rs
break; // 没有其它结果