> ## 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>
```
