例如,我有以下SQL代码:
SELECT *
FROM customer c
WHERE 2 = (SELECT count(*)
FROM account a
WHERE a.cust_id = c.cust_id);
如何将该SQL语句转换为预准备语句命令?
答案 0 :(得分: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