2014-12-11 75 views
-2
rs = stmt.executeQuery("select c1.itemname,c1.itemcalorie,p.restname,p.location from categorie1 c1 ,Place p 
where p.pincode = '" + pincode1 + "' and c1.itemid IN 
("select c1.itemid from categorie1 c1 where c1.itemcalorie <='" + cal1 + "' and c1.itemcalorie >='" + cal1-400 + "' and c1.restid = p.restid ") "); 
+6

请努力改进问题的内容和格式。提供一些细节并解释你所尝试过的。不这样做将不可避免地导致你的问题被忽略和/或关闭。如果您不确定,请参阅https://stackoverflow.com/help/how-to-ask。 – 2014-12-11 03:39:53

+1

你的'IN'子句引入了额外的引号,但是没有看到你收到的实际错误,这太难说了。 – 2014-12-11 03:41:30

+0

如果你先组装你的查询(不知何故),比如'query =“,请从categorie1 c1选择c1.itemname,c1.itemcalorie,p.restname,p.location,放置p.pincode ='”+ pincode1 +''和c1.itemid IN (“select c1.itemid from categorie1 c1 where c1.itemcalorie <='”+ cal1 +“'and c1.itemcalorie> ='”+ cal1-400 +“'and c1.restid = p.restid “)”;'然后运行它'rs = stmt.executeQuery(query);',你可以在输出你的查询并检查它是否合法... – Abecee 2014-12-11 04:04:31

回答

0

你有太多额外的引号:

rs = stmt.executeQuery(
" 
SELECT c1.itemname, 
     c1.itemcalorie, 
     p.restname, 
     p.location 
FROM categorie1 c1, 
     place p 
WHERE p.pincode = '" + pincode1 + "' 
     AND c1.itemid IN (SELECT c1.itemid 
         FROM categorie1 c1 
         WHERE c1.itemcalorie <= '" + cal1 + "' 
           AND c1.itemcalorie >= '" + cal1-400 + "' 
           AND c1.restid = p.restid) 
" 
); 

林不知道wihch语言是这样的(我希望这不是JavaScript的),但该代码是不是安全的样子转化为参数化查询。

+0

用JavaScript标记_is_标记的问题。 – JLRishe 2014-12-11 04:05:49