> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# dbNonQuery

> 对数据库执行非查询 SQL 操作语句，例如 CREATE、INSERT、UPDATE 或 DELETE。

对数据库执行非查询。仅支持 `action` SQL 语句。不支持可返回结果的 SQL 语句。

## 必需的参数

* **driver**：跨平台版本中的 JDBC 驱动程序类名称，或 .NET 版本中的 ADO.NET 提供程序名称。
* **conn**：连接字符串或数据库 URL。
* **query**：SQL 查询字符串。仅支持以下 SQL 语句：（CREATE、ALTER、DROP、INSERT、UPSERT、UPDATE、DELETE）。

## 可选的参数

* **commandtimeout**：操作完成的 CommandTimeout（以秒为单位）。零 (`0`) 表示没有超时。默认值为 `60`。
* **paramname#**：参数名称。
* **paramvalue#**：参数值。
* **paramtype#**：参数类型。
* **transactionid**：事务的 ID。此参数与 [dbBeginTransaction](./op-db-begin-transaction) 和 [dbEndTransaction](./op-db-end-transaction) 操作结合使用。
* **querypassthrough**：将查询按原样传递给操作，而不是执行客户端验证和语法纠正。
* **enforceparameterizedquery**：布尔值（true/false），用于强制对 SQL 语句进行参数化验证。默认值为 `true`。

## 输出属性

* **db:affectedrows**：查询结果影响的行数。
* **db:result**：查询执行的状态。

## 示例

此示例对目标数据库执行 CREATE 语句，以创建表和各种列定义。

```xml theme={null}
<!-- Setting the input db item and attributes -->
<arc:set attr="db.driver" value="cdata.jdbc.mysql.MySQLDriver" />
<arc:set attr="db.conn" value="jdbc:cdata:mysql:server=localhost;port=3306;database=sakila;user=root;password=Password123;"/>
<arc:set attr="db.query" value="CREATE TABLE Neighbors (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));"/>

<!-- Calling the operation, passing in the db item and setting an output item -->
<arc:call op="dbNonQuery" in="db" out="results" >
  <!-- optional logging step to see the output attributes of the query in the application log -->
  <arc:set attr="_log.info" value="[results.*]" />
</arc:call>
```

此示例对目标表执行参数化 INSERT 语句：

```xml theme={null}
<!-- Setting the input db item and attributes -->
<arc:set attr="db.driver" value="cdata.jdbc.mysql.MySQLDriver" />
<arc:set attr="db.conn" value="jdbc:cdata:mysql:server=localhost;port=3306;database=sakila;user=root;password=Password123;"/>
<arc:set attr="db.query" value="INSERT INTO Neighbors (PersonID, LastName, FirstName, Address, City ) VALUES (@param1, @param2, @param3, @param4, @param5);"/>
<arc:set attr="db.paramname#1" value="param1" />
<arc:set attr="db.paramvalue#1" value="1" />
<arc:set attr="db.paramname#2" value="param2" />
<arc:set attr="db.paramvalue#2" value="Bobby" />
<arc:set attr="db.paramname#3" value="param3" />
<arc:set attr="db.paramvalue#3" value="Ricky" />
<arc:set attr="db.paramname#4" value="param4" />
<arc:set attr="db.paramvalue#4" value="26 Wonder Bread Lane" />
<arc:set attr="db.paramname#5" value="param4" />
<arc:set attr="db.paramvalue#5" value="Charlotte" />

<!-- Calling the operation, passing in the db item and setting an output item -->
<arc:call op="dbNonQuery" in="db" out="results" >
  <!-- optional logging step to see the output attributes of the query in the application log -->
  <arc:set attr="_log.info" value="[results.*]" />
</arc:call>
```
