例如,我有以下 SQL 代码:
SELECT *
FROM customer c
WHERE 2 = (SELECT count(*)
FROM account a
WHERE a.cust_id = c.cust_id);
如何将该 SQL 语句转换为准备好的语句命令?
String queryString = " SELECT * FROM customer c";
queryString += " WHERE ? = (SELECT count(*) FROM account a WHERE a.cust_id = c.cust_id)";
PreparedStatement stmt = connection.prepareStatement(queryString);
stmt.setInt(1, theCountYouLookFor) // theCountYouLookFor would be 2 in your example