如何使用jsp。
根据在combobox中选择的值从2个mysql表中检索数据我尝试了以下代码:
sqlQuery="select a.Zone,a.Subzone,b.City from Meter_List a,Consumer b where a.Meterid=b.Meterid="+meterid ;
答案 0 :(得分:0)
你需要在WHERE部分设置:
a.Meterid = b.Meterid AND a.Meterid = ?
并使用准备好的陈述(最好是,如果有的话)。
答案 1 :(得分:0)
您可以在MeterId上加入两个表,然后使用您的输入过滤其中一个列,如下所示:
select a.Zone,a.Subzone,b.City
from
Meter_List a
JOIN Consumer b
ON a.Meterid = b.Meterid
where a.Meterid = meterid
答案 2 :(得分:0)
尝试:
sqlQuery="select a.Zone,a.Subzone,b.City from Meter_List a" +
" INNER JOIN Consumer b ON a.Meterid=b.Meterid" +
" where a.Meterid = "+meterid ;
或
sqlQuery="select a.Zone,a.Subzone,b.City from Meter_List a,Consumer b where a.Meterid=b.Meterid AND a.Meterid="+meterid ;
答案 3 :(得分:0)
这应该有效
sqlQuery="select a.Zone,a.Subzone, b.City from Meter_List AS a,
LEFT JOIN Consumer AS b ON (b.Meterid=a.Meterid) where a.Meterid=" + meterid ;
或
sqlQuery="select a.Zone,a.Subzone, b.City from Meter_List AS a,
INNER JOIN Consumer AS b ON (a.Meterid=b.Meterid) where a.Meterid=" + meterid ;