PreparedStatement 没有 ?在 where 子句中

PreparedStatement with no ? in the where clause

我知道,对于 PreparedStatement,我需要像这样

将 SQL 表达式输入 PreparedStatement
 String updateStatement =
        "update " + dbName + ".COFFEES " +
        "set TOTAL = TOTAL + ? " +
        "where COF_NAME = ?";

但是,我可以使用不带“?”的完整 where 子句来提供更新语句吗?

例如

 String updateStatement =
        "update " + dbName + ".COFFEES " +
        "set TOTAL = TOTAL + ? " +
        "where COF_NAME = 'aaa";

这只是因为我将 where 作为我的函数中的参数,我认为解析字符串以将其分解不是很有效。

使用准备语句的目的是为了拥有动态变量,但正如您所问的是否可以对整个 where 子句进行硬编码,是的,您可以对其进行硬编码。