0

例如,我有以下 SQL 代码:

SELECT * 
FROM customer c 
WHERE 2 = (SELECT count(*)
           FROM account a
           WHERE a.cust_id = c.cust_id);

如何将该 SQL 语句转换为准备好的语句命令?

4

1 回答 1

1
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
于 2013-05-16T09:00:58.027 回答