我有一個(gè)用 Java 構(gòu)建的動(dòng)態(tài)生成的 SQL 查詢。它的構(gòu)建方式是綁定一個(gè)參數(shù)數(shù)組和一個(gè)動(dòng)態(tài)創(chuàng)建的表示查詢的字符串。像這樣的東西:List<String> bindVariables;String query = "Select * from TABLE where id = ?";查詢創(chuàng)建完成后。變量根據(jù)它們?cè)跀?shù)組中的索引進(jìn)行綁定。像這樣:query = selectPortion + fromPortion + wherePortion;// Bind all parametersfor (int i = 0; i < bindVariables.size(); i++) { queryStatement.setNString(i + 1, bindVariables.get(i));}然后執(zhí)行查詢。當(dāng)我們只是將變量綁定到 WHERE 子句時(shí),這很好用,因?yàn)樗皇菍l件和變量添加到數(shù)組的末尾。但是,問題是當(dāng)我想在數(shù)組已經(jīng)有一些值之后加入變量時(shí)。wherePortion += "and table1.id = ? ";bindVariables.add("15");wherePortion += "and table2.color = ? ";bindVariables.add("blue");fromPortion += "INNER JOIN table3 on table3.size = ? ";bindVariables.add(); //Here is the issue有沒有推薦的方法來處理這種情況?
添加回答
舉報(bào)
0/150
提交
取消