本文將介紹如何在不同編程語言中開啟客戶端的PrepareStatement。

大多數(shù)數(shù)據(jù)庫中,依靠服務(wù)器端預(yù)處理語句可以提高數(shù)據(jù)庫性能。AnalyticDB MySQL數(shù)據(jù)庫自身具備強大的查詢計算能力和計劃緩存功能,無需依靠服務(wù)器端預(yù)處理語句獲得大部分性能優(yōu)勢。

AnalyticDB MySQL數(shù)據(jù)庫不建議使用服務(wù)器端預(yù)編譯。大部分開發(fā)語言中支持通過配置開啟客戶端預(yù)編譯(PrepareStatement),也稱之為客戶端準備語句仿真或參數(shù)插值。

MySQL Connector/J (JDBC) driver

在MySQL Connector/J (JDBC) driver中開啟PrepareStatement時,需要配置useServerPrepStmts=false參數(shù),詳情請參見Configuration Properties for Connector/J

說明 無需配置useCursorFetch=true參數(shù),否則將覆蓋useServerPrepStmts=false參數(shù),無法開啟PrepareStatement。

MariaDB Connector/J

在MariaDB Connector/J中開啟PrepareStatement時,需要配置useServerPrepStmts=false參數(shù),詳情請參見About MariaDB Connector/J。

Go MySQL driver

在Go MySQL driver中開啟PrepareStatement時,需要配置interpolateParams=true參數(shù),詳情請參見Go-MySQL-Driver

PDO

PDO中使用PrepareStatement時,需要配置PDO::ATTR_EMULATE_PREPARES=TRUE參數(shù),詳情請參見setAttribute。