0
例如我有以下SQL代碼:如何使用子查詢與PreparedStatements結合使用?
SELECT *
FROM customer c
WHERE 2 = (SELECT count(*)
FROM account a
WHERE a.cust_id = c.cust_id);
我怎樣才能變換SQL語句準備語句命令?
例如我有以下SQL代碼:如何使用子查詢與PreparedStatements結合使用?
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
用佔位符替換常量然後準備它們 –